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