AngularJS - 路由器的用户界面 - 定义一个通配符父状态 [英] AngularJS - Router UI - Defining a wildcard parented state

查看:165
本文介绍了AngularJS - 路由器的用户界面 - 定义一个通配符父状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,Fellaaas。
我是从我的电话写了这么请原谅我的任何东西误导或不清楚。
在我的应用程序有可以从任何其他家长的状态,叫做继承的状态交易/:dealId。
截至目前,我得一遍又一遍地定义相同的状态,了解是否有任何其他家长的状态,所以它可能是从应用程序的任何URL访问。
例如:父状态仪表板有一个孩子的状态parent.dashboard.deals,所以是另一种状态 - parent.lookup.deals,等等。
虽然谷歌搜索的解决方案,我发现在plunkr一个例子使用父状态变量定义来创建一个wildcard'ed状态的环境:
.STATE(currentState的+交易)。
男孩哦男孩,我心想。这正是我需要的。哦,不是。
我测试它,它的静态currentState的变量和它的工作就好了,以为一切我已经离开做的是动态地改变父状态了切换之间的currentState的变量。
看来,角时,产生了第一次加载路由,它采用默认的currentState的VAR作为一个字符串,并定义了状态的静态。所以,尽管我改变路线的变化之间默认的currentState的VAR,国家只提供给第一个生成状态定义。
谢谢你。

Fellas, Fellaaas. I'm writing from my phone so please excuse me for anything misleading or unclear. In my app there's a state that can be inherited from any other parent state, called "deals/:dealId:". As of now, I have to define the same state over and over again for any other parent state available, so it could be accessible from any URL on the app. For example: the parent state "dashboard" has a child state "parent.dashboard.deals", so is another state - "parent.lookup.deals", and so on. While googling for a solution I found an example on plunkr using a parent state variable definition to create a wildcard'ed state environment: .state(currentState+".deals"). "Boy oh boy", I thought to myself. That's exactly what I need. Well, not. I was testing it and it on a static "currentState" variable and it worked just fine, thought all I had left to do was to dynamically change the currentState variable between parent states switchings. It appears that when angular is generating the routes for the first time on loading, it takes the default "currentState" var as a string and defines that state static. So, even though I'm changing the default "currentState" var between route changes, the state is only available to the first generated state definition. Thank you.

推荐答案

我已经张贴在GitHub上功能请求,以防万一我在这方面的需要情况下的第一个 - 或有不正确的同时对于这个问题的解决方案:
github.com/angular-ui/ui-router/issues/1014

I've posted a feature request on GitHub, just in case I'm the first one in the need for this scenario - or there isn't a proper solution meanwhile for this problem: github.com/angular-ui/ui-router/issues/1014

总之,
我通过母国循环和静子状态连接到他们,而不是手动定义它们管理这个问题:

Anyhow, I managed this problem by looping through the parent states and attaching the static child state to them, instead of defining them manually:

  angular.forEach(states, function(stateOptions,stateName) {
 $stateProvider.state(stateName, stateOptions.options);
 if (stateOptions.defaultState){
  var dealStateName = stateName+'.deals';
  console.log(dealStateName);
    $stateProvider.state(dealStateName,{
      url: (stateName=='parent.dashboard') ? "deals/:dealId" : "/deals/:dealId",
      views:{
        'fsItem@parent':{
          templateUrl: "/static/html/fsItems/dealNewD.html",
          controller: 'dealCtrl',
        }
      }
    });
 }

});

这篇关于AngularJS - 路由器的用户界面 - 定义一个通配符父状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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