[译]Angular-ui 之 多命名视图(Multiple Named Views)

时间:2023-02-13 14:40:07

◄上一篇 (Nested States & Nested Views)     下一篇 (URL Routing) ►

  你可以给你的视图命名,以便可以在单个模版当中拥有一个以上的 ui-view 。比如说,你有一个应用需要动态生成图表,一些表的数据和过滤条件如图所示:

You can name your views so that you can have more than one ui-view per template. Let's say you had an application state that needed to dynamically populate a graph, some table data and filters for the table like this:

原文

[译]Angular-ui 之 多命名视图(Multiple Named Views)

当设置多个视图的时候,你需要在状态配置中使用view属性。view是一个对象。

Views属性将覆盖状态配置的模版属性 templateXXX

如果你定义了一个views对象,在你的状态配置中的模版类属性:templateUrltemplatetemplateProvider 将会被忽略。在这种情况下,你需要一个装载这些视图的父级布局设计,你可以定义一个抽象的状态来装载一个父模版,然后在子状态配置中声明'views'对象。

例子——Name匹配

views对象下面每一个view的名字将会用于查找你的ui-view的属性,如下:

When setting multiple views you need to use the views property on state. viewsis an object.
Views override state's template properties If you define a views object, your state's templateUrl, template andtemplateProvider will be ignored. So in the case that you need a parent layout of these views, you can define an abstract state that contains a template, and a child state under the layout state that contains the 'views' object.
Example - Name Matching The property keys on views should match your view names, like so:

原文

<!-- index.html -->
<body>
<div ui-view="filters"></div>
<div ui-view="tabledata"></div>
<div ui-view="graph"></div>
</body>
$stateProvider
.state('report', {
views: {
'filters': { ... templates and/or controllers ... },
'tabledata': {},
'graph': {},
}
})

Then each view in views can set up its own templates (template, templateUrl, templateProvider) and controllers (controller, controllerProvider).

$stateProvider
.state('report',{
views: {
'filters': {
templateUrl: 'report-filters.html',
controller: function($scope){ ... controller stuff just for filters view ... }
},
'tabledata': {
templateUrl: 'report-table.html',
controller: function($scope){ ... controller stuff just for tabledata view ... }
},
'graph': {
templateUrl: 'report-graph.html',
controller: function($scope){ ... controller stuff just for graph view ... }
},
}
})

视图的名称——相对和绝对名称(View Names - Relative vs. Absolute Names)

  在后台,每个视图都会获得一个形如‘ viewname@statename’绝对名称,viewname是指在view指令中给出的名称,statename是state的绝对名称,比如:“contact.item”。你也可以用绝对名的语法输入你的视图名。

例如,前面的例子也可以写作:

Behind the scenes, every view gets assigned an absolute name that follows a scheme of viewname@statename, where viewname is the name used in the view directive and state name is the state's absolute name, e.g. contact.item. You can also choose to write your view names in the absolute syntax.

For example, the previous example could also be written as:

原文

  .state('report',{
views: {
'filters@': { },
'tabledata@': { },
'graph@': { }
}
})

  需要注意的是现在视图名已经指定为绝对名而不是相对名称。这将会在未命名的根模版下来定位你的视图名:'filters'、 'tabledata' 和 'graph' 。因为模版未命名,所以“@”后面不需内容。那么,未命名的根模版指的就是你的index.html。绝对视图命名可以让我们有很大的权力来决定视图目标点。但是请记住:权力越大,责任越大。( Remember! With power comes responsibility )。假设,我们有几个像这样的模版(本例子不是真实的应用,只是来说明视图锚点定位):

Notice that the view names are now specified as absolute names, as opposed to the relative name. It is targeting the 'filters', 'tabledata', and 'graph' views located in the root unnamed template. Since it's unnamed, there is nothing following the '@'. The root unnamed template is your index.html.

Absolute naming lets us do some powerful view targeting. Remember! With power comes responsibility. Let's assume we had several templates set up like this (this example is not realistic, it's just to illustrate view targeting):

原文

<!-- index.html (root unnamed template) -->
<body ng-app>
<div ui-view></div> <!-- contacts.html plugs in here -->
<div ui-view="status"></div>
</body>
<!-- contacts.html -->
<h1>My Contacts</h1>
<div ui-view></div>
<div ui-view="detail"></div>
<!-- contacts.detail.html -->
<h1>Contacts Details</h1>
<div ui-view="info"></div>

让我们看一看这几个contacts.detail state下的可锚定的视图。记住如果视图名添加了"@",那么视图的路径同样认为是绝对路径:

Let's look at the various views you could target from within the contacts.detail state. Remember that if an @ is used then the view path is considered absolute:

原文

$stateProvider
.state('contacts', {
// 本模板将会自动锚定到父模版的未命名的ui-view当中(This will get automatically plugged into the unnamed ui-view of the parent state template)
// 在这里由于是在*的state配置中,因此其父模版就是index.html。(Since this is a top level state, its parent state template is index.html.)
templateUrl: 'contacts.html'
})
.state('contacts.detail', {
views: {
////////////////////////////////////
// 相对锚点查找,目标在父状态模版的ui-views当中。(Relative Targeting ,Targets parent state ui-view's )
//////////////////////////////////// // Relatively targets the 'detail' view in this state's parent state, 'contacts'.
// <div ui-view='detail'/> within contacts.html
"detail" : { }, // Relatively targets the unnamed view in this state's parent state, 'contacts'.
// <div ui-view/> within contacts.html
"" : { }, ///////////////////////////////////////////////////////
// 添加"@",导致绝对视图锚点目标查找,目标可以是本级state配 //
// 置或任意一个祖先state模板中的ui-view。 //
//(Absolute Targeting using '@' ,Target //
// any view within this state or an ancestor) //
/////////////////////////////////////////////////////// // 绝对目标是'contacts.detail'模版中名字为info的ui-view。
// <div ui-view='info'/> within contacts.detail.html
"info@contacts.detail" : { } // 绝对目标是'contacts'的模板contacts.html中的名字为'detail'的ui-view。
// <div ui-view='detail'/> within contacts.html
"detail@contacts" : { } // 绝对目标定位 'contacts’ state配置的模板'contacts.html'中的无名称的ui-view。
// <div ui-view/> within contacts.html
"@contacts" : { } // 绝对锚定目标是未命名的根state的模版也就是'index.html'中的名为'status'的ui-view视图锚点。
// <div ui-view='status'/> within index.html
"status@" : { } // 绝对目标根状态目标中的未命名ui-view。
// <div ui-view/> within index.html
"@" : { }
});

现在你应该已经看到,这种绝对视图锚点定位的能力绝不仅仅限于相同的状态配置(state config)的模板中,所有级别的祖先状态配置中的模板中的视图锚点(ui-view)都可以任开发者驰骋:)

You can see how this ability to not only set multiple views within the same state but ancestor states could become a veritable playground for a developer :).

原文

◄ Back (Nested States & Nested Views)    下一篇 (URL Routing) ►

[译]Angular-ui 之 多命名视图(Multiple Named Views)的更多相关文章

  1. &lbrack;译&rsqb;发布ABP v0&period;19包含Angular UI选项

    发布ABP v0.19包含Angular UI选项 ABP v0.19已发布,包含解决的~90个问题和600+次提交. 新功能 Angular UI 终于,ABP有了一个SPA UI选项,使用最新的A ...

  2. VueJs&lpar;11&rpar;---vue-router(命名路由,命名视图,重定向别名,路由组件传参)

    vue-router 上篇文章讲了第一篇vue-router相关文章,文章地址:VueJs(10)---vue-router(进阶1) 一.命名路由 有时候,通过一个名称来标识一个路由显得更方便一些, ...

  3. vue 命名视图

    命名视图 有时候想同时(同级)展示多个视图,而不是嵌套展示,例如创建一个布局,有 sidebar(侧导航) 和 main(主内容) 两个视图,这个时候命名视图就派上用场了.你可以在界面中拥有多个单独命 ...

  4. iOS10 UI教程基改变视图的外观与视图的可见性

    iOS10 UI教程基改变视图的外观与视图的可见性 视图是应用程序的界面,是用户在屏幕上看到的对象.用户可以通过触摸视图上的对象与应用程序进行交互,所以视图界面的优劣会直接影响到了客户体验的好坏.和视 ...

  5. 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(六)Picker View视图 学习笔记

    想对PickerView进行操作,只能在代码中操作. 下面 ,再添加三个label组件,然后将所有组件配置到代码中(看代码),然后要实现对PickerView的操作,就要实现它的DataSource协 ...

  6. 【译】UI设计基础&lpar;UI Design Basics&rpar;--导航&lpar;Navigation&rpar;&lpar;六&rpar;

    [译]UI设计基础(UI Design Basics)--导航(Navigation)(六)

  7. vue命名视图实现经典布局

    vue命名视图实现经典布局 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  8. &lbrack;mobile angular ui 1&period;2&rsqb;桌面环境下如何自动隐藏左侧的sidebar?how to hide left sidebar on desktop browser by default&quest;

    使用mobile angular ui 1.2开发,在默认情况下,桌面浏览器中sidebar-left是默认打开的,怎么才能在程序初始打开时关闭sidebar-left呢? 目前我找到的唯一可行办法就 ...

  9. vue 中 命名视图的用法

    今天主要记录  vue中命名视图的用法 先奉上官网网址:https://router.vuejs.org/zh/guide/essentials/named-views.html 一般情况下,一个页面 ...

随机推荐

  1. 关闭编辑easyui datagrid table

    var rows = dg.datagrid('getRows');    for (var i = 0; i < rows.length; i++) {        dg.datagrid( ...

  2. 【转载】 ionic 的 下拉刷新 与 上拉加载

    这篇文章是讲解 Ioinc中怎么实现 下拉刷新和上拉加载的.也是我们日常做项目是必不可少的功能.有兴趣的小伙伴可以来学习一下. 更多关于 IONIC 的资源: http://www.aliyue.ne ...

  3. 【转】NSArray排序方法

    原文网址:http://www.cnblogs.com/xiaobaizhu/archive/2013/06/05/3119983.html 从网上查的,非常方便的排序api,功能也很强大 1.sor ...

  4. LA 3704 &lpar;矩阵快速幂 循环矩阵&rpar; Cellular Automaton

    将这n个格子看做一个向量,每次操作都是一次线性组合,即vn+1 = Avn,所求答案为Akv0 A是一个n*n的矩阵,比如当n=5,d=1的时候: 不难发现,A是个循环矩阵,也就是将某一行所有元素统一 ...

  5. Spring-AOP和AspectJ的区别和联系

    AOP是Spring框架的重要组成部分.目前我所接触的AOP实现框架有Spring AOP还有就是AspectJ(还有另外几种我没有接触过).我们先来说说他们的区别: AspectJ是一个比较牛逼的A ...

  6. javascript在一个字符串中每隔多少字符插入某个字符串

    function insertStr(str,tar,n,m){ var x='' var str=str.split('') if(str.length==0) return for(var i=n ...

  7. PAT &lpar;Basic Level&rpar; Practise - 成绩排名

    1004. 成绩排名 题目链接:https://www.patest.cn/contests/pat-b-practise/1004 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓 ...

  8. C&num;实现的UDP收发请求工具类实例

    本文实例讲述了C#实现的UDP收发请求工具类.分享给大家供大家参考,具体如下: 初始化: ListeningPort = int.Parse(ConfigurationManager.AppSetti ...

  9. 搭建企业级NFS网络文件共享服务&lbrack;二&rsqb;

    1.1.8 NFS问题总结 1.问:使用showmount -e 127.0.0.1后报clnt_create: RPC: Program not registered错误 答:顺序不对,重启nfs服 ...

  10. mysql float 浮点型

    定点数类型 DEC等同于DECIMAL 浮点类型:FLOAT DOUBLE 作用:存储薪资.身高.体重.体质参数等 m,d 都是设置宽度 =============================== ...