Angularjs bootstrap dropdown not working

前端 未结 9 1938
时光取名叫无心
时光取名叫无心 2021-01-01 10:39

Am bit new to angularjs and bootstrap.

Am trying to add a simple dropdown. But it is not working.

Tried out the suggestion @ Bootstrap 3 simple dropdown not

相关标签:
9条回答
  • 2021-01-01 11:07

    You need to add on-toggle to your anchor tag, to avoid conflicts between bootstrap dropdown angular dropdown class, this issue is a closed on angular-ui(https://github.com/angular-ui/bootstrap/issues/2156)

    0 讨论(0)
  • 2021-01-01 11:10

    First make sure you included ui.bootstrap module in your app

    var app = angular.module('App', ['other inclusions','ui.bootstrap']);
    

    Then if the problem still persists don't use dropdown-toggle and dropdown as directives. Instead use as class. i.e. class = 'dropdown-toggle' etc.

    For Example :

    <div class="dropdown dropdown-append-to-body">
        <button type="button" class="btn btn-primary dropdown-toggle" data-toggle = "dropdown">Dropdown on Body <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
        </ul>
    </div>
    

    Refer this issue. https://github.com/angular-ui/bootstrap/issues/2156

    0 讨论(0)
  • 2021-01-01 11:10

    for Angular 2:

    1. add npm install ng2-bootstrap --save
    2. then follow the example from GITHUB: https://github.com/valor-software/ng2-bootstrap/tree/development/demo/components/dropdown
    0 讨论(0)
  • 2021-01-01 11:12

    Worked out pretty simple the solution (after trying to find it for ages) Simply add "dropdown-toggle" directive to your button

    <button class="btn btn-primary " dropdown-toggle type="button">Drop Me Down<span class="caret"></span></button>
    
    0 讨论(0)
  • 2021-01-01 11:16

    You need to include ui.bootstrap module in your app.

    var app = angular.module('App', ['ui.router','ui.bootstrap']);
    

    and also remove ui-sref from the dropdown trigger.

    <a class="dropdown-toggle" data-toggle="dropdown" >a<span class="caret"></span></a>
    

    Plnkr

    0 讨论(0)
  • 2021-01-01 11:23

    Well, I noticed that the attribute "dropdown" need to be added to the li element, once that is added, everything will be fine.

    <li class="dropdown" dropdown>
       <a href="#" dropdown-toggle role="button" aria-haspopup="true" aria-expanded="false">... <span class="caret"></span></a>
       <ul class="dropdown-menu">
           ...
       </ul>
    </li>
    
    0 讨论(0)
提交回复
热议问题