Bootstrap ui Collapse默认打开



我的bootstrap ui collapsed指令有问题,它显示为默认打开,我需要在页面加载时折叠,我正确设置了变量,但仍然不能正确工作

这是我的部分代码:

aside class="col-md-3 leftSidebar separator-right" ng-controller="Collapse as vm">
<div class="row separator">
    <div class="sidebarPosition">
        <div class="leftSidebar__toggle">
            <a class="mod" ng-click="vm.isCollapsedLeft = !vm.isCollapsedLeft"><span class="fa fa-bars"></span> Outline</a>
            <ul uib-collapse="vm.isCollapsedLeft">
                <li><a href="#scientific_abstract" du-smooth-scroll>Scientific Abstract</a></li>
                <li><a href="#layperson_abstract" du-smooth-scroll>Layperson’s Abstract</a></li>
                <li><a href="#introduction" du-smooth-scroll>Introduction</a></li>
                <li><a href="#">Results</a></li>
                <li><a href="#">Discussion</a></li>
                <li><a href="#">Methods</a></li>
                <li><a href="#">Additional Information</a></li>
                <li><a href="#">Change History</a></li>
                <li><a href="#">Acknowledgements</a></li>
                <li><a href="#">Author Information</a></li>
                <li><a href="#">Author Contributions</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="row leftSidebar__sections">
    <ul>
        <li><a ui-sref="article.figures"><span class="fa fa-picture-o"></span> Figures</a></li>
        <li><a ui-sref="article.references"><span class="fa fa-link"></span> References</a></li>
        <li><a href="#"><span class="fa fa-retweet"></span> Related</a></li>
        <li>
            <a href="#"> <span class="fa fa-area-chart"></span> Stats Impact</a>
        </li>
        <li><a ui-sref="article.comments"><span class="fa fa-comment"></span> Comments</a></li>
    </ul>
</div>
</aside>

我的控制器:

(function () {
'use strict';
angular
    .module('app.bootstrap')
    .controller('Collapse', Collapse);
function Collapse() {
    var vm = this;
    vm.isCollapsedLeft = false;
    vm.isCollapsedRight = false;
}
})();

下面是一个plunkr:https://plnkr.co/edit/D0vFMEQe4a2GT1yJLTLk?p=preview

谢谢你的帮助。

您说过要在页面加载时折叠它,但您正在设置vm.isCollapsedLeft = false;。设置vm.isCollapsedLeft = true;,它将在页面加载时折叠。

<html >
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style class="cp-pen-styles">.panel-heading .accordion-toggle:after {
    /* symbol for "opening" panels */
    font-family: 'Glyphicons Halflings';  /* essential for enabling glyphicon */
    content: "e114";    /* adjust as needed, taken from bootstrap.css */
    float: left;        /* adjust as needed */
    color: grey;         /* adjust as needed */
}
.panel-heading .accordion-toggle.collapsed:after {
    /* symbol for "collapsed" panels */
    content: "e080";    /* adjust as needed, taken from bootstrap.css */
}
</style>
</head>
<body>
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<div class="container">
  
  <div class="panel-group" id="accordion" aria-multiselectable="true" >
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle" data-toggle="collapse"  href="#collapseOne" >
          Collapsible Group Item #1
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in">
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle" data-toggle="collapse"  href="#collapseTwo" >
          Collapsible Group Item #2
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse in" >
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle" data-toggle="collapse" href="#collapseThree" aria-expanded="false">
          Collapsible Group Item #3
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse in" >
      <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
</div>
  
  
</div> <!-- end container -->
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body></html>

最新更新