我想使用$ resource調(diào)用我的RESTful Web服務(wù)(我仍在使用它),但是我想知道我是否首先正確地使用了AngularJS腳本。待辦事項(xiàng)DTO具有: {id, order, content, done}:cmd因此,我可以調(diào)用api/1/todo/reset以清除數(shù)據(jù)庫中的todo表。這是帶有我的理解注釋的代碼:function TodoService($resource) { var src = $resource('api/1/todo/:id:cmd', {id: "@id", cmd: "@cmd"}, //parameters default { ListTodos: { method: "GET", params: {} }, GetTodo: { method: "GET", params: { id: 0 } }, CreateTodo: { method: "POST", params: { content: "", order: 0, done: false } }, UpdateTodo: { method: "PATCH", params: { /*...*/ } }, DeleteTodo: { method: "DELETE", params: { id: 0 } }, ResetTodos: { method: "GET", params: { cmd: "reset" } }, }); //Usage: //GET without ID //it calls -> api/1/todo src.ListTodos(); //GET with ID //it calls -> api/1/todo/4 src.GetTodo({ id: 4 }); //POST with content, order, done //it calls -> api/1/todo src.CreateTodo({ content: "learn Javascript", order: 1, done: false }); //UPDATE content only //it calls -> api/1/todo/5 src.UpdateTodo({ id: 5, content: "learn AngularJS" }); //UPDATE done only //it calls -> api/1/todo/5 src.UpdateTodo({ id: 5, done: true }); //RESET with cmd //it calls -> api/1/todo/reset src.ResetTodos();}我不確定的一件事是PATCH方法,我不想更新所有內(nèi)容,可以僅更新一個(gè)字段嗎?我是否正確構(gòu)建了這段代碼?
AngularJS $ resource RESTful示例
慕村225694
2020-02-04 14:15:14