我刚开始使用 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/