栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

状态更改时,如何防止在命名视图上重新加载?AngularJS UI路由器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

状态更改时,如何防止在命名视图上重新加载?AngularJS UI路由器

ui-router
在这种情况下,我使用的方式是: 将视图移动到最小公分母

换句话说:如果

ui-view="nav"
所有细节都共享并且所有细节都相同 (因为它应该只被加载一次) -它应该是
list
状态的一部分(状态的
父对象
detail

父状态的定义将如下调整:

.state('person.list', {    url: '/list',    views: {        "main@": { templateUrl: "person.list.html", controller: 'PersonListController'        }        // here we target the person.list.html        // and its ui-view="nav"        'nav@person.list': { templateUrl: "person.nav.html", controller: 'PersonNavController'        }    }

那么诀窍在哪里?在角的力量

ui-router
。我们可以 在每个状态定义期间当前
视图作为目标。现在,该
nav
视图是
list
状态定义的一部分-即,在细节切换期间不会重新加载该视图

我们只需要使用定义的命名约定,请参阅:

  • 视图名称-相对名称与绝对名称

提到的文档中很少有引用的行:

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    "" : { },    ///////////////////////////////////////////////////////    // Absolute Targeting using '@'//    // Targets any view within this state or an ancestor //    ///////////////////////////////////////////////////////    // Absolutely targets the 'info' view in this state, 'contacts.detail'.    // <div ui-view='info'/> within contacts.detail.html    "info@contacts.detail" : { }    // Absolutely targets the 'detail' view in the 'contacts' state.    // <div ui-view='detail'/> within contacts.html    "detail@contacts" : { }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/484450.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号