我有一个AngularJS应用程序,并使用UI路由器进行路由。我的一个网页有相同的模板和逻辑两个相似的部分(所以我希望他们可以使用相同的控制器)。它们之间唯一的区别是,例如键入属性。下面是页面的简化小提琴: jsfiddle/e_gluhotorenko/XeX59/7/。
因此,是否有可能提供自定义的不同的视图数据的范围?像在美国的自定义数据但访问量:
的意见:{ SECTION1:{ templateUrl:section.html', 控制器:CTRL, 数据:{类型:TYPE1'} }, 第2节:{ templateUrl:section.html', 控制器:CTRL, 数据:{类型:'2型'} }},使用用户界面视图指令就像 NG-inclide 的的onload :
<格UI视图=SECTION1的onload =类型='1型'>< / DIV><格UI视图=2节的onload =类型='2型'>< / DIV>解决方案
刚刚发现用户界面视图实际上有的onload 属性,它是在文档不存在,但是在 REF API 。所以,我的例子,从问题的作品! 小提琴
I have an AngularJS app and use the ui-router for routing. One of my pages has two similar sections with the same template and logic (so I hope they can use the same controller). The only difference between them is for example type property. Here is simplified fiddle of the page: jsfiddle/e_gluhotorenko/XeX59/7/.
So Is it possible to provide custom different data to the views's scopes ? Something like custom data in states but for views:
views: { 'section1' : { templateUrl: 'section.html', controller : 'ctrl', data : { type: 'type1'} }, 'section2' : { templateUrl: 'section.html', controller : 'ctrl', data : { type: 'type2'} } }Or with ui-view directive like in ng-inclide's onload:
<div ui-view="section1" onload="type = 'type1'"></div> <div ui-view="section2" onload="type = 'type2'"></div>解决方案
Just found out that ui-view actually has onload attribute, it is absent in documentation but is in API ref. So my example from the question works! fiddle
更多推荐
AngularJS含自定义数据UI路由器意见
发布评论