Angular-Strap collapse plugin, opening more than one panel at the time (?)

一曲冷凌霜 提交于 2019-12-12 05:39:21

问题


Hello folks this is the plugin http://mgcrea.github.io/angular-strap/##collapses

I am trying to use this plugin in my app but isn't doing what I want, I want to use it more dynamically, as you can see in the example on the web page, you can have only one panel open at the time, and I want to give to the users the option to have open as many panels as they want, and this is my html:

  <div class="panel-group" ng-model="panels.activePanel" bs-collapse>
    <div class="panel panel-default"
      ng-repeat="sport in sports" ng-show="sport.leagues.length">
      <div class="panel-heading"
        bs-collapse-toggle
        ng-click="addSportToLines(sport)">
        <h4 class="panel-title">
          <a>
            {{::sport.name }}
          </a>
          <span class="pull-right badge">{{::sport.leagues.length }}</span>
        </h4>
      </div>
      <div class="panel-collapse" bs-collapse-target>
        <div class="panel panel-default">
            <div class="list-group">
              <a href="javascript:void(0);"
              class="list-group-item panel-padding"
              ng-repeat="league in sport.leagues"
              ng-class="{active: league.active}"
              ng-click="addLeagueToLines(league)">{{:: league.name }}</a>
            </div>
          </div>

is there a way to do it or I need to use another tool ?


回答1:


If you look at the source code for the angular-strap collapse control here, you will notice this function inside the controller:

self.$setActive = $scope.$setActive = function(value) {
    if(!self.$options.disallowToggle) {
        self.$targets.$active = self.$targets.$active === value ? -1 : value;
    } else {
        self.$targets.$active = value;
    }
    self.$viewChangeListeners.forEach(function(fn) {
        fn();
    });
};

As you can see $targets.$active is a single value, meaning that the directive only accommodates one panel open at a time. To alter the functionality of the directive, you would have to fork it and make the necessary changes.

I would look at my answer to your similar question as a better approach. You do not need a library/plugin to get the result you are looking for. See: https://stackoverflow.com/a/27611923/277697



来源:https://stackoverflow.com/questions/27610409/angular-strap-collapse-plugin-opening-more-than-one-panel-at-the-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!