找到你要的答案

Q:Dynamic view names with ui-router

Q:动态视图名称与UI路由器

I am trying to target dynamic named views in an ng-repeat but can't do so at config phase as views can only be named statically. Is there a way imitate url param matching like '/path/:param' but with view names like views: {'path:param': {...}} ?

I've tried modifying the state config object at run() to see if changing state configuration after config() had any effect:

rootScope.$on('$stateChangeStart', function(e, to, toP, from, fromP) {
  //nope
  if(toP.itemId) {
    to.views['item-'+toP.itemId+'@home'] = to.views['item-:itemId@home'];
    delete to.views['item-:itemId@home'];
  }
}

plunker: http://plnkr.co/edit/ZkrteD1ls71yd5V10Xub?p=preview

我试图在NG重复的动态命名视图的目标,但不能这样做在配置阶段视图只能静态命名。有没有一种方式模仿网址匹配像/路径/:参数但视图名称一样的看法:{ 'path:参数:{…} }?

我试着修改状态的配置对象,在run()看看改变状态的配置后config()没有任何影响:

rootScope.$on('$stateChangeStart', function(e, to, toP, from, fromP) {
  //nope
  if(toP.itemId) {
    to.views['item-'+toP.itemId+'@home'] = to.views['item-:itemId@home'];
    delete to.views['item-:itemId@home'];
  }
}

plunker:http://plnkr.co/edit/zkrted1ls71yd5v10xub?P =预览

answer1: 回答1:

This concept would not be working, in general.

The reason is that stable, solid states should not be driven by the data (which are very dynamic, changing frequently). All states and their views :{} should be defined first. The data (as a list of items) should be injected there, consuming already defined states.

  • states should be defined once (even if a bit later, once configuration is loaded via $http)
  • data could change during the application life-time often, frequently. They should be placed into states/views - but not drive them

How to load dynamic states dynamically with $http (using the .run() phase)? Check these with full examples and details:

Small extract from the doc of deferIntercept(defer):

Disables (or enables) deferring location change interception...

So, we can (once) postpone the url / location handling... to the moment, when all states are dynamically loaded. But this feature could be used just once.

Well - all that could still not fit into what we want - place some details into the list.

There is a big detail Q & A, which should give some insight:

How to replace list item with details

Please, have a look at that, because there is detailed explanation and working example...

这个概念将不会工作,一般。

原因是稳定的,固体状态不应该由数据驱动(这是非常动态的,经常变化)。所有状态及其视图:{应先定义。数据(作为项目列表)应该在那里注入,消耗已经定义的状态。

  • states should be defined once (even if a bit later, once configuration is loaded via $http)
  • data could change during the application life-time often, frequently. They should be placed into states/views - but not drive them

如何加载动态动态HTTP(使用美元。run()阶段)?检查这些完整的例子和细节:

从deferintercept DOC小提取物(推迟):

禁用(或启用)延迟位置拦截…

因此,我们可以(一次)推迟URL /位置处理…当所有状态动态加载时。但这个功能可以使用一次。

好的-所有可能仍然不适合我们想要的-把一些细节的名单。

有一个大细节问答,这应该给一些洞察力:

如何用细节替换列表项

请看一看,因为有详细的说明和工作例子…

angularjs  angular-ui-router