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

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

问题描述

我刚刚开始使用 AngularJS以下代码在控制台中给出错误.

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

未知提供者: $scopeProvider <- $scope <- newActiveOrdersModel .我已经研究过,但看起来未知提供者错误可能由于多种原因发生.如果有人能指出我哪里出错了,那就太好了?

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

似乎 Angular Js 无法识别newActiveOrdersModel".

It seems like Angular Js cannot recognize "newActiveOrdersModel".

推荐答案

这只是一个猜测,但我不知道为什么您将 $scope 列为您的服务的依赖项.我觉得是这样的

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.在 Angular 中,在 $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 抛出 Unknown provider: $scopeProvider &lt;- $scope 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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