var app=angular.module("myApp",['ng']); app.factory('$cart',['$scope',function($scope){ return { add:function(){ $scope.pList.push({price:8000,count:Math.floor(Math.random()*100+1)}); }, del:function(index){ $scope.pList.splice(index,1); } } }]); app.controller('myCtrl',['$scope','$cart',function($scope,$cart){ $scope.pList=[ {price:2000,count:Math.floor(Math.random()*100+1)}, {price:3000,count:Math.floor(Math.random()*100+1)}, {price:5000,count:Math.floor(Math.random()*100+1)}, {price:9000,count:Math.floor(Math.random()*100+1)} ]; $scope.handleAdd=function(){ $cart.add(); }; $scope.handleDelete=function(){ $cart.del(); } }]);这段代码会报如下错误:angular.js:12314 Error: [injector:unpr]Unknownprovider:scopeProvider <- scope<−cart;刚学angular 求大神知道π-π
添加回答
举报
0/150
提交
取消