我想删除购物车中的商品。为此,我使用函数canceldummy()作为单个项目。我的问题在于,删除时出现错误...
NewOrderFactory.deleteDummyOrder is not a function
at deleteDummy (TiffinServices.js:55)
at Scope.$scope.canceldummy (TiffinControllers.js:357)
at fn (eval at <anonymous> (angular.js:13365), <anonymous>:4:651)
at callback (angular.js:23613)
at Scope.$eval (angular.js:16052)
at Scope.$apply (angular.js:16152)
at HTMLAnchorElement.<anonymous> (angular.js:23618)
at HTMLAnchorElement.n.event.dispatch (jquery-2.2.0.min.js:3)
at HTMLAnchorElement.r.handle (jquery-2.2.0.min.js:3)
html代码:
<a href="" title="Remove item" class="button remove-item" ng-click="canceldummy($index)"><span><span>Remove item</span></span></a>
这是我的控制器代码。
mainCtrl.controller("OrderController",function($scope,NewOrderService){
$scope.canceldummy=function(idx){
NewOrderService.deleteDummy(idx);
}
})
这是我的服务代码
servctrl.service("NewOrderService",function(NewOrderFactory){
this.deleteDummy=function(idx){
NewOrderFactory.deleteDummyOrder(idx);
}
})
这是我的Factorys代码
factmodule.factory("NewOrderFactory",function(){
var OrderItemList={Items:[]}
return{
deleteDummyOrder: function(idx){
OrderItemList.Items.splice(idx,1);
}
}
})
如何删除此错误?
答案 0 :(得分:0)
我认为错误出在工厂,在您的工厂中尝试此代码:
factmodule.factory("NewOrderFactory",function(){
var OrderItemList={Items:[]};
OrderItemList.deleteDummyOrder: function(idx){
OrderItemList.Items.splice(idx,1);
}
return OrderItemList;
})