AngularJS含自定义数据UI路由器意见

编程入门 行业动态 更新时间:2024-10-24 23:30:08
本文介绍了AngularJS含自定义数据UI路由器意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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路由器意见

本文发布于:2023-11-25 14:14:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630082.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   路由器   意见   数据   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!