2017-04-04 57 views
1

在這段代碼中,控制器被提供的注入範圍和rootScope,爲何還未能與最後一行:如何在Angular中訪問此rootScope?

的ReferenceError:$ rootscope沒有定義

angular.module("myEntity").controller('productsCtrl', [ 
    '$scope', 'MyAction', '$rootScope', function ($scope, MyAction, $rootScope) { 
     $scope.propertyValue = something; 
     $scope.canDoSomething = $rootscope.myRootScopeProperty = 1; 
     .... 
+4

它是''''rootScope'''(大寫字母S),你有一個錯字。 – Dario

回答

4

只是轉換這個

$rootscope 

這個

$rootScope 
0

這裏的錯誤是$ rootscope,所以我們需要將其更改爲$ rootScope,

問題:

$scope.canDoSomething = $rootscope.myRootScopeProperty = 1; 

ReferenceError: $rootscope is not defined

解決方案:

$scope.canDoSomething = $rootScope.myRootScopeProperty = 1;