asp.net web api - angular.js:13424 TypeError: $scope.entry.update is not a function. Updating the correct way with angularjs -
i trying make update existing object following error $scope.entry.update not function
.
i created service called 'budgetresource'
"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 } }); }
herewith function in controller budgetresource service injected function $scope.updatebudgetamount being called.
$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; }); }
which in turn calls webapi method
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); }
how can modify dine correctly?
after $scope.entry = {...}
,$scope.entry
becomes plain javascript object, $scope.entry.update
not exist.
Comments
Post a Comment