2
我想在保存新對象後向表中添加一個新行。 的例子如下:AngularJS RESTful Web服務 - 無刷新地將行添加到表
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);
// I want to avoid this method to refresh my 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
}
});
});
有沒有辦法做到這一點無需再作查詢到我的數據庫,以示我的表中的新行?
它的作品,謝謝哥們。 – wilson
你能幫我解決這種類似的情況嗎?謝謝。 http://stackoverflow.com/questions/30573582/angularjs-restful-web-service-delete-row-from-table – wilson
我喜歡@andrunix第二個答案。使用您在刪除調用中使用的標識,並根據該標識刪除集合中的對象。 –