简体   繁体   English

Bootstrap NavBar崩溃在默认的angular-fullstack生成的代码中不起作用

[英]Bootstrap NavBar collapse not working in a default angular-fullstack generated code

I have recently started working on a MEAN stack app and generated some boilerplate code using angular-fullstack. 我最近开始研究MEAN堆栈应用程序,并使用angular-fullstack生成了一些样板代码。 On running grunt serve, a default app actually had collapsing feature of bootstarp library. 在运行grunt服务时,默认应用实际上具有bootstarp库的折叠功能。 On reducing the size of window, the navigation collapses and button appears on it. 减小窗口大小时,导航折叠并在其上显示按钮。 But due to some issue, the clicking functionality is not working. 但是由于某些问题,单击功能不起作用。 Whenever I click on the button, nothing happens. 每当我单击按钮时,什么都不会发生。

div.navbar.navbar-default.navbar-static-top(ng-controller='NavbarCtrl')
  div.container
    div.navbar-header
      button.navbar-toggle(type='button', ng-click='isCollapsed = !isCollapsed')
        span.sr-only Toggle navigation
        span.icon-bar
        span.icon-bar
        span.icon-bar
      a.navbar-brand(href='/') scrub

    div#navbar-main.navbar-collapse.collapse(collapse='isCollapsed')
      ul.nav.navbar-nav
        li(ng-repeat='item in menu', ng-class='{active: isActive(item.link)}')
          a(ng-href='{{item.link}}') {{item.title}}

        li(ng-show='isAdmin()', ng-class='{active: isActive("/admin")}')
          a(href='/admin') Admin

      ul.nav.navbar-nav.navbar-right
        li(ng-hide='isLoggedIn()', ng-class='{active: isActive("/signup")}')
          a(href='/signup') Sign up

        li(ng-hide='isLoggedIn()', ng-class='{active: isActive("/login")}')
          a(href='/login') Login

        li(ng-show='isLoggedIn()')
          p.navbar-text Hello {{ getCurrentUser().name }}

        li(ng-show='isLoggedIn()', ng-class='{active: isActive("/settings")}')
          a(href='/settings')
            span.glyphicon.glyphicon-cog

        li(ng-show='isLoggedIn()', ng-class='{active: isActive("/logout")}')
          a(href='', ng-click='logout()') Logout

controller.js controller.js

'use strict';

angular.module('scrubApp')
  .controller('NavbarCtrl', function ($scope, $location, Auth) {
    $scope.menu = [{
      'title': 'Home',
      'link': '/'
    }, {
      'title': 'Solutions',
      'link': '/solutions'      
    }, {
      'title': 'Plans',
      'link': '/plans'
    }, {
      'title': 'About Us',
      'link': '/about'
    }];

    $scope.isCollapsed = true;
    $scope.isLoggedIn = Auth.isLoggedIn;
    $scope.isAdmin = Auth.isAdmin;
    $scope.getCurrentUser = Auth.getCurrentUser;

    $scope.logout = function() {
      Auth.logout();
      $location.path('/login');
    };

    $scope.isActive = function(route) {
      return route === $location.path();
    };
  });

Anyone with any idea what can be possibly wrong ? 有任何想法的人可能有什么错误吗?

You need to have UI-Bootstrap included. 您需要包含UI-Bootstrap。

https://github.com/angular-fullstack/generator-angular-fullstack/issues/458 https://github.com/angular-fullstack/generator-angular-fullstack/issues/458

And depending on your version of UI-Bootstrap you might have to modify 根据您的UI-Bootstrap版本,您可能需要修改

collapse='isCollapsed'

to

uib-collapse ='isCollapsed'

A bit late but I have just come across this problem myself. 有点晚了,但我本人只是遇到了这个问题。 I fixed it by adding the following CSS styles: 我通过添加以下CSS样式对其进行了修复:

.navbar-collapse {
    height: auto !important;
}

.collapsing {
    height: auto !important;
    position: static !important;
}

The problem seems to be that the 'collapsing' class never disappears from the navbar and it also has height: 0px on there too which is preventing it from displaying properly. 问题似乎是'collapsing'类永远不会从导航栏中消失,并且它也具有height: 0px也位于其上,这妨碍了其正常显示。 It works before building the app though (using grunt serve ) so something in the grunt process must break it. 尽管它可以在构建应用程序之前运行(使用grunt serve ),所以在grunt过程中必须将其破坏。

Ps The position: static property isn't necessary, but I also found that the navbar-brand was unclickable unless I added that too. Ps position:静态属性不是必需的,但是我也发现navbar-brand是不可点击的,除非我也添加了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM