【发布时间】:2018-11-14 22:16:00
【问题描述】:
我正在使用 Angular JS 练习 $rootscope。这里我定义rootscope如下
var sample=angular.module("sample",[]).run(['$rootscope', function($rootScope){
$rootScope.months=12;
}])
这个根作用域在内部作用域中调用如下
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
我的代码有什么问题?
【问题讨论】:
标签: javascript angularjs