2013-10-18 58 views
2

我有一個服務,我打電話來獲得一個集合,它工作正常。下面是該服務:

angular.module('clinicalApp').factory('encounterService', function ($resource, $rootScope) { 
    var EncounterService = $resource('http://localhost:port/v2/encounters/:encounterId', {encounterId:'@id', port: ':8280'}, { 
    search: { 
     method: 'GET', 
     headers: { 
     'User': 'testuser', 
     'Content-Type': 'application/json' 
     } 
    }, 
    save: { 
     headers: { 
     'User': 'testuser', 
     'Content-Type': 'application/json' 
     } 
    } 
    }); 

    return EncounterService; 
}); 

正如我所說的,我能得到回收,但是當我嘗試更新的元素的一個在我的收藏,它呼喚着錯誤的URL。這裏是我正試圖拯救我的資源:

encounterService.save({ 
    id: scope.encounter.id 
}); 

這裏是正在熱播的網址:

http://localhost:8280/v2/encounters?id=12345

所以它是附加的URL,就好像它是一個搜索參數。我如何得到它的ID添加到URL,像

encounters/12345

,因爲它應該?

回答

0

嘗試......

{encounterId:'@id', port: ':8280'} 

更改爲:

{encounterId:'@encounterId', port: ':8280'} 

encounterService.save({ 
    id: scope.encounter.id 
}); 

更改爲:

encounterService.save({ 
    encounterId: scope.encounter.id 
}); 
+0

這窩糟透了。你能解釋一下嗎? – jhamm

+0

是的。 meetId會一樣 –