ui路由器中templateUrl从一种状态到另一种状态的动态变化 [英] dynamic change of templateUrl in ui-router from one state to another
问题描述
html:
<a ui-sref="user.tools.selectedTemplate({provider: t.id})" target="_blank">{{t.name}}</a>
以上代码在ng-repeat中,其中包含许多带有名称和ID的模板链接,因此当我单击每个链接时,href将会更新,其中ID号会附加到所选模板链接上.我正在使用相同的控制器生成大约十个模板.我正在将ui-sref中的值从一种状态传递到另一种状态,因此我需要动态templateUrl, 我尝试了链接问题,但是自从模板页面没有参数.
Above code is in ng-repeat with many template links loaded with name and id so when i click each link , href will be updated with id number appended to selected template link. I am generating about ten templates with same controller. I am passing value in ui-sref from one state to another so i need dynamic templateUrl, i tried this link issue but i cant able to send stateparams since the main template page has no params.
这是app.js中的ui路由器代码
Here the ui router code in app.js
.state('user.tools.template',angularAMD.route({
url: '/template',
templateUrl: './views/tools/select-template.html',
controller: 'selectTplCtrl',
controllerUrl: 'tools/selecttplCtrl'
}))
.state('user.tools.selectedTemplate',angularAMD.route({
url: '/selectedTemplate/:provider',
templateUrl: function($stateParams){
return './views/tools/selected-template'+'$stateParams.provider'+'.html'
},
controller: 'selectedTemplateCtrl',
controllerUrl: 'tools/selectedTemplateCtrl'
}))
任何人都可以解决此问题吗?
Can anyone solve this issue ?
推荐答案
我会说你走在正确的轨道上.只是应该对URL结构进行如下调整:
I would say that you are on the right track.. just URL construction should be adjusted like this:
templateUrl: function($stateParams){
//return './views/tools/selected-template'+'$stateParams.provider'+'.html'
return './views/tools/selected-template'+ $stateParams.provider +'.html'
}
在此处查看更多信息,使用动态模板链接时我们可以使用UI-Router:
See more here, what we can have with UI-Router when working with dynamic template link:
- Angular UI Router-动态TemplateURL
- Angular UI Router:基于父解析对象决定子状态模板
- Angular和UI-Router,如何设置动态templateUrl
- Angular UI Router - Dynamic TemplateURL
- Angular UI Router: decide child state template on the basis of parent resolved object
- Angular and UI-Router, how to set a dynamic templateUrl
这篇关于ui路由器中templateUrl从一种状态到另一种状态的动态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!