我正在使用angular $ resource。这是我的服务:
.factory('EventSubCategory', function($resource) {
// Might use a resource here that returns a JSON array
return $resource("http://localhost:3000/api/event_sub_categories");
// Some fake testing data
})
这是我称之为的控制器:
.controller('ActivityDashboardCtrl', function($scope, $state, EventCategory, EventForm, EventSubCategory) {
$scope.createSubCategory = function(sub_categories){
console.log(sub_categories);
EventSubCategory.$save(sub_categories);
}
})
但是,当我这样做时,我在浏览器控制台中收到此错误:
ionic.bundle.js:25642 TypeError: EventSubCategory.$save is not a function
at Scope.$scope.createSubCategory (controllers.js:43)
at fn (eval at <anonymous> (ionic.bundle.js:26457), <anonymous>:4:362)
at callback (ionic.bundle.js:36610)
at Scope.$eval (ionic.bundle.js:29158)
at Scope.$apply (ionic.bundle.js:29257)
at HTMLFormElement.<anonymous> (ionic.bundle.js:36615)
at HTMLFormElement.eventHandler (ionic.bundle.js:16583)
at triggerMouseEvent (ionic.bundle.js:2948)
at tapClick (ionic.bundle.js:2937)
at HTMLDocument.tapMouseUp (ionic.bundle.js:3013)
我尝试将控制器更改为:
答案 0 :(得分:1)
将sub_categories设为资源实例,然后调用$ save()
var categories = new EventSubCategory(sub_categories);
categories.$save();