Skip to content

Instantly share code, notes, and snippets.

@xjinza
Created July 3, 2018 07:54
Show Gist options
  • Save xjinza/a397225b0d9d2290808a1cdebfa91d99 to your computer and use it in GitHub Desktop.
Save xjinza/a397225b0d9d2290808a1cdebfa91d99 to your computer and use it in GitHub Desktop.
angularjs run config 拦截器引入$scope 报错#angularjs
angularjs在初始化run或者config拦截器$httpProvider.interceptors里引入$scope会报错$scope Unknown provider: $scopeProvider
app.run([
'httpService','$timeout','$rootScope','$scope', function(httpService,$timeout,$rootScope,$scope) {
$rootScope.tokenNew = 'test1';
$timeout(function() {
$rootScope.$broadcast('getToken',$rootScope.tokenNew);
},2000)
}]);
只能用$rootScope, 比如用angular.element('body').scope()就会报undefined.
app.run(function ($rootScope) {
$rootScope.someData = {message: "hello"};
});
You can only get $rootScope injected to services and run function, because each child scope is inherited from its parent scope and the top level scope is rootScope. Since it would be ambigous to inject any scope. Only root scope is provided.
参考:https://stackoverflow.com/questions/17371687/getting-scope-object-in-angulars-run-method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment