我学习AngularJS并收到以下错误13920类型错误在AngularJS
angular.js:13920TypeError:CRUDService.ShoppingList_InsertUpdate不是一个函数
下面是我控制器
app.controller('addShopItem', ['$scope', '$http', 'CRUDService', 'uiGridConstants', function ($scope, $http, CRUDService, uiGridConstants) {
var apiRoutePost = 'http://localhost:vvvvv/api/ShoppingListAPI/Post/';
$scope.addShoppingItem = function() {
CRUDService.ShoppingList_InsertUpdate(apiRoutePost, $scope.ShoppingList);
};
}]);
和我的CRUDService javascript
app.service('CRUDService', function ($http) {
//**********----Get Shopping List Items----***************
$scope.getShoppingListItems = function (apiRoute) {
return $http.get(apiRoute);
}
//**********----Insert Shopping List Items----***************
$scope.ShoppingItems.InsertUpdate = function (apiRoutePost, data) {
return $http.post(apiRoutePost, data);
}
});
欣赏帮助
看看构建'services'的正确方法 - https://docs.angularjs.org/guide/services。范围的目的是将应用程序的表示和业务逻辑“粘合在一起”。将$范围传递给服务没有多大意义。避免在服务级别使用'$ scope'。 –
我不认为你正在创建你的服务。 $范围从哪里来?自从我写了一篇,但看看文档已经有一段时间了。 –