导航菜单下拉列表不工作Angular2 Bootstrap 3

时间:2017-03-21 17:17:26

标签: twitter-bootstrap angular

angular-2中有一个项目,并使用bootstrap作为css框架。但是,我无法让导航下拉列表工作。我已经按照指南here来安装bootstrap,但它不起作用。即使是他们所提供的例子也不起作用。我做错了什么?

菜单组件html

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
        aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a [routerLink]="['home']"><img src="./assets/images/just-health-logo-colour.png" /></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a [routerLink]="['home']"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Home</a></li>
        <li><a>Link</a></li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a><span class="glyphicon glyphicon-user" aria-hidden="true"></span></a></li>
        <li><a [routerLink]="['help']"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a></li>
      </ul>
      <form class="navbar-form navbar-right">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>

    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>

1 个答案:

答案 0 :(得分:0)

<nav class="navbar navbar-default">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="col-sm-12 collapse navbar-collapse pull-right" id="myNavbar">
            <ul class="nav navbar-nav ">
                <li class="">
                    <a routerLink="/login">Login</a>
                </li>
                <li class="">
                    <a routerLink="/logout">Logout</a>
                </li>
                <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Dropdown<span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a routerLink="/menu1">menu-1</a></li>
          <li><a routerLink="/menu2">menu-2</a></li>
        </ul>
      </li>
            </ul>
        </div>
    </nav>

以下是使用angular2中的bootstrap导航栏的示例,您可以使用这段代码