【问题标题】:Deactivating Ui-router's ui-sref-active on root state on a nested configuration在嵌套配置的根状态下停用 Ui-router 的 ui-sref-active
【发布时间】:2015-06-06 13:47:41
【问题描述】:

我有 2 个按钮,并且都有 ui-sref-active。

<a class="button" ui-sref-active="button-selected" ui-sref="main">
    <p>View patients</p>
</a>
<a class="button" ui-sref-active="button-selected" ui-sref="main.create">
    <p>Add patients</>
</a>

和css

.button-selected {
    color: #0000FF;
}

我想知道为什么当我单击状态为“main.create”的第二个按钮时,没有从第一个按钮中删除“button-selected”类。所以在第一个按钮上仍然可以看到颜色#0000FF。看起来“主要”状态始终处于活动状态。是因为它是根状态吗?解决方法是什么?

【问题讨论】:

    标签: angularjs angular-ui-router ui-sref


    【解决方案1】:

    该类已添加到两种状态,因为您应该使用 ui-sref-active-eq 而不是 ui-sref-active

    <a class="button" ui-sref-active-eq="button-selected" ui-sref="main">
        <p>View patients</p>
    </a>
    <a class="button" ui-sref-active-eq="button-selected" ui-sref="main.create">
        <p>Add patients</>
    </a>
    

    【讨论】:

    • 哇哦!太感谢了!为什么我发现的 Angular 文档使用 ui-sref-active 而不是 ui-sref-active-eq?
    • 您使用的是ui-router 对吗?可能是因为正常情况是您使用 ui-sref-active 在主要状态而不是状态父母和他的孩子之间进行时尚导航。 W
    猜你喜欢
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 2014-12-16
    • 2015-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多