javascript - AngularJS RESTful Web Service - Add row to table without refresh -


i'm trying add new row table after save new object. example follow:

var demoapp = angular.module("demoapp", ["ngresource"]);  // controller demoapp.controller("savecategorycontroller", function($scope, savecategoryservice, categoriesservice){     $scope.categories = categoriesservice.query();      $scope.createcategory = function(){         savecategoryservice.savecategory($scope.category);         // want avoid method refresh table.         // $scope.categories = categoriesservice.query();      };     });  // factory demoapp.factory("savecategoryservice", function($resource){     return $resource("/demopro/savecategory", {}, {         savecategory: {             method: "post"         }     }); });  demoapp.factory("categoriesservice", function($resource){     return $resource("/demopro/categories", {}, {         listallcategories : {             method: "get",             isarray: true         }     });  }); 

is there way without make again query database in order show new row in table?

yes, logically return saved object on save , add current list:

$scope.createcategory = function(){         var newcategory = savecategoryservice.savecategory($scope.category);         $scope.categories.push(newcategory);      };    

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -