14
A
回答
13
最好的解釋===
例如:
// by writing '{ id: '@id' }' we want the id to be taken from 'id' parameter in request data, hence the '@' sign. Note that this mechanism is available for non-GET RQs only:
var Notes = $resource('/notes/:id', { id: '@id' });
var noteId = "my_note1";
// below we specify 'id' explicitly - has to be done for GET RQ:
// operations on our note are done inside callback function, just to make sure that the note is resolved:
var note = Notes.get({ id: noteId }, function() {
// let's make some changes:
note.topic = "A brand new topic here!";
// save using $resource "static" action (aka "class" action). 'id' is taken from data object:
Notes.save(note);
// We can overwrite 'id' just like this:
Notes.save({ id: "some_other_noteId" }, note);
// even more changes:
note.body = "Blah blah blah, new boring body is here";
// this time save using instance action. Again: 'id' is taken from data object:
note.$save();
// changing id with instance action? there you go:
note.$save({ id: "yet_another_noteId" });
// Naturally, we could just:
note.id = "OMG_how_many_of_those_noteIds_has_he_left";
Notes.save(note);
// ... and with instance action:
note.id = "OK_he_wins";
note.$save();
});
甚至是自定義$resource
動作(由您定義)有自己的$
-prefixed同行,只要他們不GET - 。見http://docs.angularjs.org/api/ngResource.$resource#example_creating-a-custom-put-request。
不,並非所有操作都有實例方法版本。在實例上調用GET
會有什麼意義?從官方ngResource
文檔:
類對象或實例對象上的動作的方法可以使用以下參數來調用:
- HTTP GET「類」動作:Resource.action([參數]非GET GET「類」操作:Resource.action([參數],postData,[成功],[錯誤])
- 非GET實例操作:實例。$ action ([參數],[成功],[錯誤])
0
$save
是通過$resource
的動作添加的方法。保存可以是特殊資源的一種方法。
所有操作都有$
前綴方法。在這裏閱讀更多:http://docs.angularjs.org/api/ngResource $資源
相關問題
- 1. AngularJS - 範圍差異
- 2. AngularJS對象差異
- 3. 如何保存文本差異?
- 4. 差異保存和saveOrUpdate方法冬眠
- 5. Laravel驗證差異更新和保存
- 6. AngularJs依賴注入差異
- 7. Ansible庫存差異
- 8. 差異保留重複
- 9. 差異之間保持
- 10. AngularJS:$ scope。$ on和document.addEventListener之間的差異
- 11. AngularJS 2日期之間的差異
- 12. AngularJS addRow並保存
- 13. 存在差異和EXISTS
- 14. 存儲時間差異Django
- 15. IoC生存期差異
- 16. Eclipse Maven存儲庫差異
- 17. 爲什麼差異顯示這兩個文件存在差異?
- 18. 保存後UIImage質量差
- 19. PHP日期差異,保存在陣列之間的每一天
- 20. 比較兩個文件,並保存在Linux的差異
- 21. 將項目保存爲增量json差異?
- 22. 保存svg到磁盤作爲PNG圖像 - 瀏覽器差異
- 23. 新的+保存和創建rails之間的差異
- 24. Github將差異保存到文件並共享
- 25. libgit2sharp帶有未保存文件的Tree的差異
- 26. 提示,點擊差異標籤,保存之前
- 27. 在內存中保持文件差異的好方法
- 28. 差異 - 文件差異
- 29. AngularJs:在angularJs本地保存數據
- 30. 使用Date vs DateTime時是否存在性能差異或存儲差異?