AngularJS含自定义数据UI路由器意见 [英] AngularJS ui-router views with custom data

查看:162
本文介绍了AngularJS含自定义数据UI路由器意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AngularJS应用程序,并使用UI路由器进行路由。我的一个网页有相同的模板和逻辑两个相似的部分(所以我希望他们可以使用相同的控制器)。它们之间唯一的区别是,例如键入属性。下面是页面的简化小提琴: http://jsfiddle.net/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: http://jsfiddle.net/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路由器意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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