2017-06-14 71 views
0

當我嘗試在下面提供的代碼我收到錯誤添加$scope

angular.module('starter', ['ngRoute', 'ngAnimate', 'myApp.controllers']) 
    .run(['$window', '$location', '$rootScope', '$scope', function ($window, $location, $rootScope, $scope) {}]); 

錯誤:

Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.2.26/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope 

回答

1

您不能將$scope注入運行組件。或者,您必須使用$rootScope。因爲頂級範圍是rootScope並且所有子範圍都是從它繼承的

angular.module('starter', ['ngRoute', 'ngAnimate', 'myApp.controllers']) 
    .run(['$window', '$location', '$rootScope', function ($window, $location, $rootScope) { 

}]); 
相關問題