简体   繁体   English

角度UI路由器嵌套视图功能

[英]Angular UI-router nested views capabilities

I am trying to learn and understand the capabilities of UI-router with Angular 1.3.15. 我正在尝试学习和理解Angular 1.3.15的UI路由器的功能。

I am trying to set up an application which has many views that have a header and footer directive. 我试图建立一个应用程序,该应用程序具有许多具有页眉和页脚指令的视图。 It also has a smaller number of views that do not need this setup, with the loaded view taking up the entire page. 它还具有少量不需要此设置的视图,加载的视图占据了整个页面。

Therefore, it seems I should handle this divergence "one level down", as in my diagram below. 因此,似乎我应该处理这种“向下一级”的分歧,如下图所示。 In the past, I have worked on ui-router apps with the index.html coded with the header/footer directives and a single ui-view for the other pages to load into. 过去,我使用ui-router应用程序进行工作,其中index.html使用header / footer指令编码,并且单个ui视图供其他页面加载。 This time I am trying to get it correct form the start. 这次,我试图从开始就使其正确。 Opinions and advice welcome. 欢迎意见和建议。

在此处输入图片说明

I'm not sure what you want to know. 我不确定您想知道什么。

Yeah, you should handle the difference in templates the way you suggested: the root template should contain only the elements which appear on all states. 是的,您应该按照建议的方式处理模板中的差异:根模板应仅包含出现在所有状态的元素。 Elements which appear on some states should go on those states templates, in the template of a parent state (if it makes sense), or in directives that you reuse in the various templates. 出现在某些状态上的元素应放在这些状态模板上,在父状态模板中(如果有意义)或在各种模板中重用的指令中。

Instead of directives, you might want to use named views if your templates have some peatures in common, but the differences between them are not inside a single DOM element. 如果模板具有一些共同的特征,则可能要使用命名视图 ,而不是指令,但是它们之间的区别不在单个DOM元素内。 For example, maybe all your pages have a small toolbar on top that always has some buttons, but other buttons depend on the state you are in. You can place that constant part of the toolbar in the root template, together with a <div ui-view="toolbar"></div> . 例如,也许您的所有页面的顶部都有一个小的工具栏,该工具栏总是有一些按钮,但是其他按钮取决于您所处的状态。您可以将工具栏的该恒定部分与<div ui-view="toolbar"></div>一起放置在根模板中<div ui-view="toolbar"></div> The states would then define a view named toolbar with a template with the buttons they want to add. 然后,各州将定义一个名为toolbar的视图,该视图带有一个模板以及要添加的按钮。

You could make a directive for that toolbar with all the global buttons in its template and use <ng-transclude> to add the custom buttons at each state's template, but using named views seems cleaner. 您可以为该工具栏指定模板中的所有全局按钮的指令,并使用<ng-transclude>在每个州的模板上添加自定义按钮,但是使用命名视图似乎更简洁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM