带有 ui-router 的动态视图名称
Dynamic view names with ui-router
我正在尝试在 ng-repeat 中以动态命名视图为目标,但不能在配置阶段这样做,因为视图只能静态命名。有没有办法模仿 url 参数匹配 '/path/:param'
但视图名称像 views: {'path:param': {...}}
?
我试过在 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'];
}
}
一般来说,这个概念是行不通的。
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
如何使用 $http
(使用 .run()
阶段) 动态加载动态状态?用完整的例子和细节检查这些:
- AngularJS - UI-router - How to configure dynamic views
- 文档:$urlRouterProvider.deferIntercept(defer)
deferIntercept(defer)
文档的小节选:
Disables (or enables) deferring location change interception...
所以,我们可以(一次) 推迟 url /位置处理...到现在,当所有状态都是动态加载的。但是这个功能只能使用一次。
嗯 - 所有这些仍然不能满足我们的要求 - 将一些细节放入列表中。
有一个很大的细节Q & A,应该可以提供一些见解:
How to replace list item with details
拜托,有一个look at that,因为有详细的解释和工作示例...
我正在尝试在 ng-repeat 中以动态命名视图为目标,但不能在配置阶段这样做,因为视图只能静态命名。有没有办法模仿 url 参数匹配 '/path/:param'
但视图名称像 views: {'path:param': {...}}
?
我试过在 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'];
}
}
一般来说,这个概念是行不通的。
The reason is that stable, solid
states
should not be driven by thedata
(which are very dynamic, changing frequently). Allstates
and theirviews :{}
should be defined first. Thedata
(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 intostates/views
- but not drive them
如何使用 $http
(使用 .run()
阶段) 动态加载动态状态?用完整的例子和细节检查这些:
- AngularJS - UI-router - How to configure dynamic views
- 文档:$urlRouterProvider.deferIntercept(defer)
deferIntercept(defer)
文档的小节选:
Disables (or enables) deferring location change interception...
所以,我们可以(一次) 推迟 url /位置处理...到现在,当所有状态都是动态加载的。但是这个功能只能使用一次。
嗯 - 所有这些仍然不能满足我们的要求 - 将一些细节放入列表中。
有一个很大的细节Q & A,应该可以提供一些见解:
How to replace list item with details
拜托,有一个look at that,因为有详细的解释和工作示例...