簡體   English   中英

$ rootscope在角度Js中拋出錯誤

[英]$rootscope throwing error in angular Js

我在Angular JS中練習$rootscope 在這里,我定義如下的rootscope

var sample=angular.module("sample",[]).run(['$rootscope', function($rootScope){
            $rootScope.months=12;
        }]) 

而這個rootscope調用內部范圍如下

sample.controller('salary', ['$scope','$rootscope', function($rootScope,$scope){
            $scope.dept="developer";
            $scope.salary=58900
            $scope.getAnualSalary=function () {
                return (this.salary)*$rootScope.months;
            }
        }])

但我沒有顯示期望的結果並在控制台中引發錯誤

angular.js:14800錯誤:[$ injector:unpr] http://errors.angularjs.org/1.6.9/ $ injector / unpr?p0 =%24rootscopeProvider%20%3C-%20%24rootscope%20%3C- %20salary

完整的代碼在這里

我的代碼有什么問題?

更改訂單。 參數和字符串值的順序必須相同

sample.controller('salary', ['$scope','$rootScope', function($scope, $rootScope){

正確的注射器是$ rootScope (區分大小寫)

var sample=angular.module("sample",[]).run(['$rootScope', function($rootScope){

字符串和函數參數的順序也應該相同

sample.controller('salary', ['$scope','$rootScope', function($scope, $rootScope){

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM