2016-04-01 37 views
0

我想刪除購物車中的物品。爲此,我使用函數canceldummy()作爲單個項目。在這裏我的問題是,在刪除我得到一個錯誤......factory.function不是angularjs中的函數

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); 
    } 
}) 

這是我,廠區代碼

factmodule.factory("NewOrderFactory",function(){ 
    var OrderItemList={Items:[]} 
    return{ 
     deleteDummyOrder: function(idx){ 
      OrderItemList.Items.splice(idx,1); 
     } 
    } 
}) 

如何消除這種錯誤?

+1

創建plunker –

回答

0

我認爲錯誤是在工廠,試試這個代碼在你的工廠:

factmodule.factory("NewOrderFactory",function(){ 

    var OrderItemList={Items:[]}; 
    OrderItemList.deleteDummyOrder: function(idx){ 
     OrderItemList.Items.splice(idx,1);  
    } 
    return OrderItemList; 
})