您的位置:首页技术文章
文章详情页

javascript - angular js Unknown provider错误

浏览:45日期:2023-04-25 13:18:58

问题描述

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] Unknown provider: $scopeProvider <- $scope <- $cart;刚学angular 求大神知道π-π

问题解答

回答1:

谢邀。factory、service 只有$rootScope,没办法知道局部的$scope的。

标签: JavaScript
相关文章: