0
既存のオブジェクトを更新しようとしましたが、次のエラーが発生しました$scope.entry.update is not a function
。
私はbudgetResourceサービスが呼び出される関数$ scope.updateBudgetAmountを注入された私のコントローラ内の関数同封
"use strict";
angular.module("common.services").factory("budgetResource", ["$resource", "appSettings", budgetResource])
function budgetResource($resource, appSettings) {
return $resource(appSettings.serverPath + "api/budget/:id", null,
{
'update': { method: 'PUT', isArray: true },
'delete': { method: 'DELETE', isArray: true },
'save': { method: 'POST', isArray: true }
});
}
「budgetResource」と呼ばれるサービスを作成しました。今度はWEBAPI方法が正しく食事をされるように、これを変更するにはどうすればよい
public IHttpActionResult Put(int id, [FromBody]Category cat)
{
try
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
BudgetRepository repo = new BudgetRepository();
var categories = repo.SaveCategory(cat);
return Ok(categories);
}
を呼び出し
$scope.updateBudgetAmount = function (categoryId) {
$scope.entry = new budgetResource();
$scope.entry = {
"budgetAmount": $scope.budgetAmount,
"categoryId": categoryId
}
$scope.entry.update({ id: categoryId },
function (data) {
$scope.categories = data;
$scope.category = "";
},
function (error) {
$scope.message = error.statusText;
});
}
?
ありがとうございました。この$ scope.entry。$ update({id:categoryId}、このトリックを行った – Arianule