Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular UI Bootstrap responsive Navbar dropdown not working properly in new version

I just created an AngularJS project with grunt bower and Yeoman. Included Updated version to Angular 1.3.13. I want to use Angular UI bootstrap. I added Nav Bar which is responsive. But while on small screens, the drop down doesn't seem to work. When I click on dropdown the entire menu hides.

here is my index.html

<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css(.) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- endbower -->
<!-- endbuild -->
<!-- build:css(.tmp) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
<body ng-app="webClientApp">
    <!--[if lt IE 7]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->

    <!-- Add your site or application content here -->
    <header>
        <nav class="navbar navbar-default" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">

                <button type="button" class="navbar-toggle"
                    ng-init="navCollapsed = true"
                    ng-click="navCollapsed = !navCollapsed">
                    <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="#/">Web Client</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse"
                ng-class="!navCollapsed && 'in'" ng-click="navCollapsed=true">

                <ul class="nav navbar-nav">
                    <li class="active"><a href="">Link</a></li>
                    <li><a href="">Link</a></li>

                    <li class="dropdown"><a href="" class="dropdown-toggle" data-toggle="dropdown">Dropdown
                            <b class="caret"></b>
                    </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><a href="">Separated link</a></li>
                            <li><a href="">One more separated link</a></li>
                        </ul></li>

                </ul>
                <form class="navbar-form navbar-left" role="search">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search">
                    </div>
                    <button type="submit" class="btn btn-default">Submit</button>
                </form>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="">Link</a></li>
                    <li class="dropdown"><a href="" class="dropdown-toggle"
                        data-toggle="dropdown">Dropdown <b class="caret"></b></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><a href="">Separated link</a></li>
                        </ul></li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </nav>
    </header>
    <div class="container">
        <div ng-view=""></div>
    </div>

    <div class="footer">
        <div class="container">
            <p>
                <span class="glyphicon glyphicon-heart"></span> from the Yeoman team
            </p>
        </div>
    </div>


    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
    <script>
        !function(A, n, g, u, l, a, r) {
            A.GoogleAnalyticsObject = l, A[l] = A[l] || function() {
                (A[l].q = A[l].q || []).push(arguments)
            }, A[l].l = +new Date, a = n.createElement(g), r = n
                    .getElementsByTagName(g)[0], a.src = u, r.parentNode
                    .insertBefore(a, r)
        }(window, document, 'script',
                '//www.google-analytics.com/analytics.js', 'ga');

        ga('create', 'UA-XXXXX-X');
        ga('send', 'pageview');
    </script>

    <!-- build:js(.) scripts/vendor.js -->
    <!-- bower:js -->
    <script src="bower_components/jquery/dist/jquery.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
    <script src="bower_components/angular-animate/angular-animate.js"></script>
    <script src="bower_components/angular-cookies/angular-cookies.js"></script>
    <script src="bower_components/angular-resource/angular-resource.js"></script>
    <script src="bower_components/angular-route/angular-route.js"></script>
    <script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
    <script src="bower_components/angular-touch/angular-touch.js"></script>
    <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
    <!-- endbower -->
    <!-- endbuild -->

    <!-- build:js({.tmp,app}) scripts/scripts.js -->
    <script src="scripts/app.js"></script>
    <script src="scripts/controllers/main.js"></script>
    <script src="scripts/controllers/about.js"></script>
    <!-- endbuild -->
</body>
</html>

I'm using all latest versions of JS. Here is my bower.json

{
  "name": "web-client",
  "version": "0.0.0",
  "dependencies": {
    "angular": "^1.3.13",
    "bootstrap": "^3.3.2",
    "angular-animate": "^1.3.13",
    "angular-cookies": "^1.3.13",
    "angular-resource": "^1.3.13",
    "angular-route": "^1.3.13",
    "angular-sanitize": "^1.3.13",
    "angular-touch": "^1.3.13",
    "angular-bootstrap": "0.12.1"
  },
  "devDependencies": {
    "angular-mocks": "^1.3.13"
  },
  "appPath": "app",
  "moduleName": "webClientApp"
}

The nav bar on full screen is working fine. But when I resize the browser size, The responsive bar is working. Menu will show up only on clicking the toggle buton. But when I click on drop down menu, the entire menu hides.

I have followed this StackOverflow Question and I got one Plunker Demo for it. It is working fine there.

But I'm using Latest versions of all files. So mine is not working. Here is my code what I tried in Plnker.

How to Solve this Issue? Thanks.

like image 685
iCode Avatar asked Feb 23 '15 05:02

iCode


People also ask

Why dropdown is not working in bootstrap angular?

Solution : The dropdown should be toggled via data attributes or using javascript. In the above program, we have forgotten to add a data attribute so the dropdown is not working. So add data-bs-toggle="dropdown" to toggle the dropdown.

How to make bootstrap dropdown responsive?

If you want to use responsive alignment, disable dynamic positioning by adding the data-display="static" attribute and use the responsive variation classes. To align right the dropdown menu with the given breakpoint or larger, add .


1 Answers

Your dropdown portion has changed.

Here's a Plunker

<li dropdown>
     <a href="#" dropdown-toggle>Dropdown <b class="caret"></b></a>
     <ul class="dropdown-menu">
          <li><a href="#">...</a></li>
          ....
     </ul>
</li>
like image 131
Dylan Avatar answered Oct 11 '22 23:10

Dylan