javascript - AngularJS 抛出未知提供者 : $scopeProvider <- $scope error when I try to use modules

标签 javascript angularjs

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

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

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”。

最佳答案

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

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

将解决错误。另外,除非您绝对需要,否则我不会包含 $rootScope。在 Angular 中,将内容存储在 $rootScope 中通常被认为是不好的做法。

关于javascript - AngularJS 抛出未知提供者 : $scopeProvider <- $scope error when I try to use modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19546032/

相关文章:

angularjs - 未使用 Angular $http 设置 Content-Type header

angularjs - 从父元素触发子元素中的 ng-click

javascript - 如何在 ionic 3 中将视频文件从 ios 转换为 base64

javascript - Typescript:将 HTMLElement 转换为 Node

javascript - Angular 按钮正在调用表单提交按钮,原因未知

angularjs - 如何在 rxjs Observable 中包装 Angular $http promise 调用时刷新 View

javascript - angularJs 形式未正确将对象添加到数组中。 2 路绑定(bind)不起作用

javascript - 如何从外部文件更改标记为 var 的函数?

javascript - PlayStation 4 互联网浏览器上的 Vuejs 和 Bootstrap 4

javascript - 了解 window.onerror