2015-04-17 84 views
1

我已經使用引導程序插件來摺疊並展開<div> s。我能夠爲個人<div>做到這一點,但如果我將其中一個<div>展開並做了collapseAll(),則展開的<div>只會變得崩潰。請給我提供這個角度崩潰全部不起作用

HTML的解決方案:

<body ng-controller="MainCtrl"> 
    <div class="panel panel-default" ng-repeat="item in items"> 
     <div class="panel-heading" ng-click="isCollapsed = !isCollapsed">{{item.title}}</div> 
     <div class="panel-body" collapse="isCollapsed">{{item.content}}</div> 
    </div> 
    <div> 
     <input type="checkbox" id="collapse_all_cards" ng-model="isCollapsed"><label for="collapse_all_cards">Collapse All</label> 
    </div> 
</body> 

JS:

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

app.controller('MainCtrl', function($scope) { 
    $scope.items = [{'title':'Item1','content':'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus maximus orci sodales, pellentesque urna eu'}, 
       {'title':'Item2','content':'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus maximus orci sodales, pellentesque urna eu'}, 

       {'title':'Item3','content':'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus maximus orci sodales, pellentesque urna eu'} 

      ] 
}); 

鏈接:http://plnkr.co/edit/mcnqeLJcTyaAuTI9JHb9

回答

2

請參閱本Plunk

很肯定這是水煤漿你是在:)

之前的問題是,範圍中的相同「isCollapsed」屬性被用於「全部摺疊」,並且單個摺疊使得它們彼此絆倒。

見它有一個單獨的布爾新的控制器代碼「isCollapsed」屬性集合中的每個項目:

{'title':'Item1','content':'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus maximus orci sodales, pellentesque urna eu', isCollapsed: true} 

如果您需要任何改進的代碼只是問:)

+1

這正是我在尋找。非常感謝 :) – user1153484