Struggling with a challenge for two days now, I have attempted to implement a panel-box using bootstrap and AngularJS. Within the confines of a controller, my code looks like this:
<div id="menu2a">
<div class="panel list-group">
<div class="list-group-item"><b>Panel Title</b></div>
<div class="panel-body" data-toggle = "collapse" data-target = '#1'
title = "click for more information">
<span
class="glyphicon glyphicon-chevron-down pull-right"></span>
<ul>
<li data-ng-repeat="element in UnknownSizeArray">
<i>{{$index + 1}}) {{element}}</i>
</li>
</ul>
<div style = "padding-left:40px" id="1" class = "collapse">
<br>
<p> More information here..</p>
</div>
</div>
</div>
</div>
The content to display is stored in UnknownSizeArray
and is passed from an Angular controller to the HTML page.
My current obstacles include:
Implementing collapsibility based on the amount of content (e.g. show additional elements in the collapsible box if over 5 array elements).
Removing the chevron glyphicon when collapsibility is not needed.
Adjusting the height of the
panel-body
to accommodate 3-5 elements without collapsing.
How can I address these challenges efficiently?
Attempts using jQuery's .css()
and .attr()
functions in a JavaScript file, along with data-ng-init = "test()"
, did not yield the desired results. See below one of the attempts made:
$scope.test = function() {
var array = $scope.UnknownSizeArray;
if (array.length > 5) {
$(".panel-body").attr("data-toggle","collapse");
};
};
Why didn't this approach work, and what would be a more suitable solution?