Angular-资源:.$save 不是函数
Angular-resource: .$save is not a function
我正在使用 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)
我试过将我的控制器更改为:
创建sub_categories一个资源实例,然后调用$save()
var categories = new EventSubCategory(sub_categories);
categories.$save();
我正在使用 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)
我试过将我的控制器更改为:
创建sub_categories一个资源实例,然后调用$save()
var categories = new EventSubCategory(sub_categories);
categories.$save();