【问题标题】:how to highlight nav tab state1 when we are in state3当我们处于状态3时如何突出显示导航选项卡状态1
【发布时间】:2017-03-16 22:16:02
【问题描述】:

当我们在state3 中使用ui-router 概念时,我需要突出显示导航选项卡state1State3state1 html 中。

下面是我的代码:

<nav> 
    <a ui-sref="state1" ui-sref-active="active">State 1</a>
    <a ui-sref="state2" ui-sref-active="active">State 2</a>
</nav>

<div ui-view></div>

myApp.config(function ($stateProvider, $urlRouterProvider){
    $stateProvider.state("state1", {
        url: "#",
        template: "<p>State 1 <a ui-sref='state3'>details</a></p>",
      })
      .state("state2", {
        url: "#",
        template: "<p>State 2</p>",
      })
      .state('state3', {
            url: "#",
            template: "<h2>state1 details</h2>",
        });
});

JSFiddle

谢谢。

【问题讨论】:

  • 我不知道 ui-sref-active 的概念。但是通过使用 jquery 你可以做到。 jsfiddle.net/akhilap/2cbtLtdt/3
  • @AkhilaPrakash 很好,但我正在寻找 angularjs 解决方案
  • 我会尽力帮助你的。

标签: angularjs html angular-ui-router


【解决方案1】:

查看您的代码的替代方案。我添加了指向 0.2.15 版 angular-router 的链接,并为子视图添加了一个 ui-view 控件。适合吗?

<nav> 
    <a ui-sref="state1" ui-sref-active="active">State 1</a>
    <a ui-sref="state2" ui-sref-active="active">State 2</a>
</nav>

<div ui-view></div>

var myApp = angular.module("myApp",[ "ui.router", "AppCtrls"]);

myApp.config(function ($stateProvider, $urlRouterProvider){
    $stateProvider.state("state1", {
        url: "/state1",
        template: "<p>State 1 <a ui-sref='.state3'>details</a><ui-view /></p>",
      })
      .state("state2", {
        url: "/state2",
        template: "<p>State 2</p>",
      })
      .state('state1.state3', {
            url: "/state3",
            template: "<h2>state1 details</h2>",
        });
});

var ctrls = angular.module("AppCtrls", []);

http://jsfiddle.net/jahn08/f1owscs5/

【讨论】:

  • 感谢您的宝贵时间,但这里我不能使用嵌套视图
猜你喜欢
  • 2016-06-29
  • 2017-11-05
  • 1970-01-01
  • 2019-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-22
  • 1970-01-01
相关资源
最近更新 更多