AngularJS抛出未知提供商:$ scopeProvider< - $范围错误,当我尝试使用模块 [英] AngularJS throws Unknown provider: $scopeProvider <- $scope error when I try to use modules

查看:241
本文介绍了AngularJS抛出未知提供商:$ scopeProvider< - $范围错误,当我尝试使用模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始用AngularJS
下面code给出了控制台错误。

I have just started with AngularJS The following code gives an error in the console.

未知提供商:$ scopeProvider< - $范围< - newActiveOrdersModel。我已经研究,但它看起来可能发生的各种reasons.It的未知的提供程序错误将是很好,如果有人能指出我要去的地方错了?

Unknown provider: $scopeProvider <- $scope <- newActiveOrdersModel . I have researched but it looks like Unknown Provider error can happen for a variety of reasons.It would be nice if anyone could point out where I am going wrong ?

var app;
(function(angular){

    app = angular.module('OrdersDashboard',[]);
    app.config(['$routeProvider', function($routeProvider) {
        $routeProvider.
            when('/current/new', {templateUrl: 'orders/partials/new_current', controller: 'newActiveOrdersCtrl'}).
            otherwise({redirectTo: '/'});
    }]);
    app.service('newActiveOrdersModel', ['$scope', '$rootScope',
        function($scope, $rootScope){

            this.Orders=["This is a test order"];
            this.fetchOrders = function(){

                console.log("This is a test order");
                this.Orders=["This is a test order1111"];
            };
        }]);
    app.controller('newActiveOrdersCtrl', ['$scope', '$rootScope', 'newActiveOrdersModel',
        function($scope, $rootScope, newActiveOrdersModel){

            $scope.test="Hello World";
        }]);

})(angular);

好像角的js无法识别newActiveOrdersModel。

It seems like Angular Js cannot recognize "newActiveOrdersModel".

推荐答案

这只是一种猜测,但我不知道为什么你列为你的服务的依赖$范围。我觉得像这样

This just a guess but I don't know why you have $scope listed as a dependency of your service. I think something like this

 app.service('newActiveOrdersModel', ['$rootScope',
    function($rootScope){..}]

将解决这个错误。此外,我将不包括$ rootScope,除非你绝对需要它。它通常被认为是不好的做法在角存储的东西在$ rootScope。

will solve the error. Also I wouldn't include $rootScope unless you absolutely need it. It's generally considered bad practice in Angular to store stuff in the $rootScope.

这篇关于AngularJS抛出未知提供商:$ scopeProvider&LT; - $范围错误,当我尝试使用模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆