什么是设置$ rootScope的目的$状态= $状态。具有角的UI用户界面,路由器?
我的code有以下几点:
My code has the following:
var app = angular.module('app', ['admin', 'home', 'questions', 'ui.compat', 'ngResource', 'LocalStorageModule']);
app.run(['$rootScope', '$state', '$stateParams', function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
$state.transitionTo('home');
}]);
有人能解释什么先从$ rootScope两条线都在做。他们是否需要?
Can someone please explain what the two lines starting with $rootScope are doing. Are they needed?
本评论是从示例源$ C $ C采取项目github上页:
This comment is taken from example source code on projects github page:
这是非常方便的,以$状态和引用$ stateParams添加到$ rootScope
这样就可以从你的应用程序中的任何范围访问它们。例如,
<李纳克级={活跃:$ state.includes('contacts.list')}>
将设置<李>
为主动每当contacts.list或它decendents之一是有效的。
It's very handy to add references to $state and $stateParams to the $rootScope so that you can access them from any scope within your applications. For example,
<li ng-class="{ active: $state.includes('contacts.list') }">
will set the<li>
to active whenever 'contacts.list' or one of its decendents is active.
您可以检查出来这里