管理我的父母 - 子女状态时遇到问题,主要是因为我是ui-router的新手。但是,我已经完成了研究并找到了需要对路由进行硬编码但不是动态的解决方案。Angular UI路由器ng-if当前确切状态
我目前有:
<div> <!-- parent state -->
<div ng-if="'.' | isState">
<!--
background hierarchy that should be visible only when
parent state is active and not a child state of the parent
-->
</div>
<nav>
<a ui-sref="." ui-sref-active="active">Parent</a>
<a ui-sref=".child1" ui-sref-active="active">Child 1</a>
<a ui-sref=".child2" ui-sref-active="active">Child 2</a>
</nav>
<div ui-view></div>
</div>
我试图完成? 当父代加载时,我希望背景显示一些内容。它占据了整个屏幕。 ui-view
不会占用整个屏幕。因此,当路线与父母的状态不完全匹配时,我希望隐藏或移除背景元素(如果父母的路线是/root/parent
,我希望背景仅在状态恰好为/root/parent
而不是/root/parent/child1
时可见)。
我能够实现我想要的只有当我提供确切的预期路线。例如ng-if="'root.parent' | isState"
。
此外,ui-sref-active="active"
保留active
类显示子视图时(这是预期的,但我希望班级只有在路线完全匹配时才有效)。
但是,我不认为这是很好的父母路线的硬编码视图。我只是想让它匹配它所属的任何路线。因此,如果我稍后决定将其移至/root/parent/car
,则不必更新ng-if
和ui-sref-active
以反映更改。
有没有人遇到问题,并能够解决它?
你有父母子女等级的原因是什么? – arqam
从子路径'Child 1'中删除'active'类并将'css'添加到'active'类,以便它只出现在背景中。 – Sravan
@arqam页面的主要内容实际上显示为背景,并且子项包含可隐藏的可选内容。 – DraganTL