0
web服務,我有以下不那麼寧靜API,我必須與角的$資源映射:轉發查詢字符串的參數與AngularJS
GET /api/posts/:id
GET /api/list_posts/:kind
其中第二路線返回每個職位匹配:kind
。
客戶端,與AngularJS,我想用這些更傳統的路線:
index.html#/posts/:id
index.html#/posts?kind=...
我如何定義,其中kind
被轉發到一個web服務資源$?
我試過以下,但很可惜,角度不明白我的意思:kind
:
appServices.factory('Post', ['$resource',
function ($resource) {
return $resource('/api/posts/:id', {}, {
query: {url: '/api/list_posts/:kind'}
});
}])
編輯:實例
如果我有index.html#/posts?kind=42
在我的地址欄,然後應該以這種方式查詢API:/api/list_posts/42
。
如果我在我的地址欄中有index.html#/posts/42
,那麼應該以這種方式查詢API:/api/posts/42
。