Bootstrap-ui和移动菜单

时间:2015-03-09 19:15:26

标签: angularjs twitter-bootstrap

我遇到的问题是,在小型设备/屏幕上移动菜单(3行)在点击时什么都不做。也没有错误。我已经尝试了很多我已经看过的解决方案但却无法工作的东西 - 决心不再回到JQ

HTML:

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" ng-controller="NavBarCtrl">
<div class="container">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" ng-init="isCollapsed = false" ng-click="isCollapsed = !isCollapsed">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="#">
      <img src="/images/logo/logo.png" href="/caption-it/" class="logo img-responsive"> <span class="hidden-xs hidden-sm">Bring your photos to life</span>
    </a>
  </div>
  <div collapse="isCollapsed" class="collapse navbar-collapse navbar-ex1-collapse">
    <ul class="nav navbar-nav navbar-right">
      <li><a href="#captionIt"><i class="fa fa-home"></i> Home</a></li>
      <li><a href="/caption-it/facebook-photos"><i class="fa fa-facebook whiteText"></i> <span class="hidden-xs hidden-sm hidden-md">Facebook </span>Photos</a></li>
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-list"></i> My Captionise <b class="caret"></b></a>
        <ul class="dropdown-menu">
          <li><a href="#uploadPhotos">Upload Photos</a></li>
          <li><a href="#myUploadedPhotos">My Uploads</a></li>
          <li><a href="#myCaptionised">My Captionised Photos</a></li>
        </ul>
      </li>
      <li class="hidden-xs hidden-sm hidden-md hidden-lg"><a href="/caption-it/browser-button">Browser Button</a></li>
      <li><a href="#" onclick="logOut(); return false"><i class="fa fa-sign-out"></i> Sign Out</a></li>
    </ul>
  </div>
</div>

角:

var capApp = angular.module('capApp', ['ngRoute','ui.bootstrap','ngCookies']);

function NavBarCtrl($scope) {
  $scope.isCollapsed = true;
}

我尝试过使用和不使用bootstra.js,但没有区别。

只有(一周)开始使用Angular。

真的在挣扎这个想法吗?

1 个答案:

答案 0 :(得分:2)

这是我目前工作的有效解决方案。

看看

 <div id="navbar" class="navbar-collapse" ng-class="{'collapse':!isCollapsed}">

<nav class="navbar navbar-inverse navbar-fixed-top" ng-init="isCollapsed = false">

无需在控制器中指定。选择是你初始化的地方。

 <nav class="navbar navbar-inverse navbar-fixed-top" ng-init="isCollapsed = false">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" ng-click="isCollapsed = !isCollapsed" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
          <a class="navbar-brand" ng-click="getactivemenu('')" ui-sref="home">Site Name</a>
    </div>
    <div id="navbar" class="navbar-collapse" ng-class="{'collapse':!isCollapsed}">
      <ul class="nav navbar-nav navbar-right">
        <li  ng-click="isCollapsed = !isCollapsed" ><a ui-sref="enquiries">Menu 1</a></li>
        <li  ng-click="isCollapsed = !isCollapsed" ><a ui-sref="enquiries">Menu 2</a></li>
        <li  ng-click="isCollapsed = !isCollapsed" ><a ui-sref="enquiries">Menu 3</a></li>
        <li  ng-click="isCollapsed = !isCollapsed" ><a ui-sref="enquiries">Menu 4</a></li>
                  </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>