切换按钮不适用于AngularJS和Angular ui Bootstrap

时间:2014-02-04 00:48:02

标签: angularjs twitter-bootstrap navbar togglebutton angular-ui-bootstrap

出现切换按钮但不起作用。我现在在网上也有相同的代码而且它不起作用但是在Plunker它正在工作。

Plunker - toggle button is working

Same code online - button is not working

代码是:

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <div class="nalogo-wrapper">
                    <img class="img-responsive" src="http://placehold.it/50x50&text=Logo" />
                </div>
            </div>
            <div class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li><a href="#/view1"><span class="glyphicon glyphicon-home"></span> Etusivu</a></li>
                    <li><a href="#/view2">Palvelut</a></li>
                    <li><a href="#/view3">Yhteistiedot</a></li>
                </ul>
            </div><!--/.nav-collapse -->
        </div>
    </div>
    <div id="main">
        <div ng-view>
        </div>
    </div> 

感谢您的帮助! 萨米

3 个答案:

答案 0 :(得分:8)

我刚从一个使用angular-ui bootstrap的工作项目中复制了它:

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle btn navbar-btn" 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="/#">Bake-Off</a>
        </div>
        <div collapse="navCollapsed" class="navbar-collapse collapse navbar-responsive-collapse">
            <ul class="nav navbar-nav">
                <li><a href="#" >Link 1</a></li>
                <li><a href="#" >Link 2</a></li>
                <li></li>
            </ul>
            <div class="container navbar-form navbar-right">

            </div>
        </div>
        <!--/.navbar-collapse -->
    </div>
</div>

答案 1 :(得分:1)

您必须对导航栏进行一些更改,以适应Angular UI-Bootstrap的折叠指令。不久前我自己也在想这个问题,这个问题已经在这里被问到并回答了:

Responsive dropdown navbar with angular-ui bootstrap (done in the correct angular kind of way)

答案 2 :(得分:0)

为Josh C的答案添加替代解决方案,根据最新文档将崩溃更改为uib-collapse

https://angular-ui.github.io/bootstrap/#!#collapse

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle btn navbar-btn" 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="/#">Bake-Off</a>
        </div>
        <div uib-collapse="navCollapsed" class="navbar-collapse collapse navbar-responsive-collapse">
            <ul class="nav navbar-nav">
                <li><a href="#" >Link 1</a></li>
                <li><a href="#" >Link 2</a></li>
                <li></li>
            </ul>
            <div class="container navbar-form navbar-right">

            </div>
        </div>
        <!--/.navbar-collapse -->
    </div>
</div>