1

一旦我使用 $http 调用我所有的 API 端点。但最近我读到使用 $resource 更加健壮或最佳实践。现在我正在将我所有的 $http 调用迁移到 $resource 并且我对如何使 $resource 函数动态化感到困惑。

My api endpoint
GET: /broadcast/{gameId}
GET: /broadcast/{gameId}/players
POST: /broadcast/{gameId}/audio
POST: /broadcast/{gameId}/play/control
GET: /broadcast/{gameId}/remaining
etc..

这就是我制作工厂 $resource 的方式

Broadcasting: function() {
        return $resource(api+"broadcast/:gameId", {},
            { 
              getByGameId    : {method: "GET", isArray: false},
              getByPlayers : {method: "GET", isArray: false}, //how to add additional URI for /players
              postAudio : {method: "POST", isArray: false},//how to add additional URI for /audio
              postControl     : {method: "POST", isArray: false}, //how to add additional URI for /play/control
             getRemaining     : {method: "GET", isArray: false} //how to add additional URI for /remaining
            }
        );
      }

谢谢

4

0 回答 0