角度资源动态uri

时间:2014-02-25 03:24:47

标签: angularjs angularjs-resource angularjs-http

一旦我使用$ http来调用我所有的apis'端点。但最近我读到使用$ 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..

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

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
            }
        );
      }

感谢

0 个答案:

没有答案