[英]$rootscope throwing error in angular Js
I'm practicing $rootscope
in Angular JS. 我在Angular JS中练习
$rootscope
。 Here I'm defining rootscope
as below 在这里,我定义如下的
rootscope
var sample=angular.module("sample",[]).run(['$rootscope', function($rootScope){
$rootScope.months=12;
}])
And this rootscope calling in inner scope as below 而这个rootscope调用内部范围如下
sample.controller('salary', ['$scope','$rootscope', function($rootScope,$scope){
$scope.dept="developer";
$scope.salary=58900
$scope.getAnualSalary=function () {
return (this.salary)*$rootScope.months;
}
}])
but I doesn't showing desired result and throwing error in console 但我没有显示期望的结果并在控制台中引发错误
angular.js:14800 Error: [$injector:unpr] http://errors.angularjs.org/1.6.9/ $injector/unpr?p0=%24rootscopeProvider%20%3C-%20%24rootscope%20%3C-%20salary
angular.js:14800错误:[$ injector:unpr] http://errors.angularjs.org/1.6.9/ $ injector / unpr?p0 =%24rootscopeProvider%20%3C-%20%24rootscope%20%3C- %20salary
what's the wrong in my code? 我的代码有什么问题?
change the order. 更改订单。 You need to have the same order in both arguments and string values
参数和字符串值的顺序必须相同
sample.controller('salary', ['$scope','$rootScope', function($scope, $rootScope){
Correct injector is $rootScope (case sensitive) 正确的注射器是$ rootScope (区分大小写)
var sample=angular.module("sample",[]).run(['$rootScope', function($rootScope){
Also the order should be same in strings and function arguments 字符串和函数参数的顺序也应该相同
sample.controller('salary', ['$scope','$rootScope', function($scope, $rootScope){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.