angular js Unknown provider error - Stack Overflow
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-30 09:55:05
0
1
696
    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();
        }
    }]);

This code will report the following error: angular.js:12314 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- $cart;
Just now Learn angular and ask the master to know π-π

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(1)
为情所困

Thanks for the invitation.
factory and service only have $rootScope, so there is no way to know the local $scope.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template