什么是设置$ rootScope的目的$状态= $状态。具有角的UI用户界面,路由器? [英] What's the purpose of setting $rootScope.$state = $state; with angular-ui ui-router?

查看:138
本文介绍了什么是设置$ 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.

您可以检查出来这里

这篇关于什么是设置$ rootScope的目的$状态= $状态。具有角的UI用户界面,路由器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆