UI-Bootstrap Accordion Directive not working - angularjs

I downloaded the angularjs UI Bootstrap accordion directive found here: UI Bootstrap
However, I cannot get it to work and the <accordion> tag generates errors. I included the ['ui.bootstrap'] dependency in my angular module and I put references to files directly on page. Can anyone tell me what I am missing?
Here is my module:
var myApp = angular.module("dashboardManagement", ['ui.bootstrap'])
Here is my view:
#section scripts{
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-animate.js"></script>
<script src="~/Scripts/app/app.js"></script>
<script src="~/Scripts/app/Contractor/contractorController.js"></script>
<script src="~/Scripts/app/Contractor/contractorService.js"></script>
<script src="~/Scripts/ui-bootstrap-custom-tpls-0.13.3.js"></script>
<script src="~/Scripts/app/Test/AccordionDemoCtrl.js"></script>
}
<h2>Index</h2>
<div ng-app="dashboardManagement">
<div>
<div>
<div ng-controller="AccordionDemoCtrl">
<p>
<button type="button" class="btn btn-default btn-sm" ng-click="status.open = !status.open">Toggle last panel</button>
<button type="button" class="btn btn-default btn-sm" ng-click="status.isFirstDisabled = ! status.isFirstDisabled">Enable / Disable first panel</button>
</p>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="oneAtATime">
Open only one at a time
</label>
</div>
<accordion close-others="oneAtATime">
<accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">
This content is straight in the template.
</accordion-group>
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">
{{group.content}}
</accordion-group>
<accordion-group heading="Dynamic Body Content">
<p>The body of the accordion group grows to fit the contents</p>
<button type="button" class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button>
<div ng-repeat="item in items">{{item}}</div>
</accordion-group>
<accordion-group is-open="status.open">
<accordion-heading>
I can have markup, too! <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
</accordion-heading>
This is just some content to illustrate fancy headings.
</accordion-group>
</accordion>
</div>
</div>
`

there's a couple of different issues I can see here. First is, you are including both the minified and unminified versions of these resources, so you have the same code twice. So make sure to just include <script src="~/Scripts/ui-bootstrap-custom-tpls-0.13.3.js"></script> and remove the other three similar overlapping scripts. Are you also including Angular above these scripts? because that is a dependency and will throw errors if not included before
second, is the provided example code what you're actually using? Because of course just having this:
<accordion>
</accordion>
will not do very much. You have to provide content for this directive like:
<accordion>
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">
{{group.content}}
</accordion-group>
</accordion>
Check out the plnkr demo for full working example code:
http://plnkr.co/edit/MlcqWL?p=preview

What I discovered is that the Accordion feature is not working as expected because my _Layout.cshtml has a nav-sidebar in it. If I comment out the navbar, the Accordion works as expected. I plan to post a "new" question regarding the found issue.

Related

AngularJS nested accordions with ng-repeat

I have a 4 level model, for which I need to create nested accordions. However I cannot figure out why when I click on a Child, all of the sibbligs open (or close).
I'm using ui.bootstrap. Here's the code I'm using (the short versiĆ³n anyway):
<div ng-controller="ProgramasController as vm">
<accordion>
<accordion-group ng-repeat="programa in programas" is-open="status.open">
<accordion-heading>
<i class="fa fa-lg" ng-class="{'fa-minus-circle': status.open, 'fa-plus-circle': !status.open}"></i> {{programa.xrmName}}
</accordion-heading>
<accordion close-others="false">
<accordion-group ng-repeat="tipoDeAtencion in tiposDeAtencion" is-open="status.innerOpen">
<accordion-heading>
<i class="fa fa-lg" ng-class="{'fa-minus-circle': status.innerOpen, 'fa-plus-circle': !status.innerOpen}"></i> {{tipoDeAtencion.xrmName}}
</accordion-heading>
<div>
algo
</div>
</accordion-group>
</accordion>
</accordion-group>
</accordion>
</div>
Each programa in your programas is using the same status.open variable.
I think you want to switch to using an attribute of the programa itself like programa.open; note that you may want to initialize the field to false in each.
You will need to apply the same change for status.innerOpen and switch it to tipoDeAtencion.open.
You might want to use property from the iterating object to handle the open status as follows:
<div ng-controller="ProgramasController as vm">
<accordion>
<accordion-group ng-repeat="programa in programas" is-open="programa.open">
<accordion-heading>
<i class="fa fa-lg" ng-class="{'fa-minus-circle': programa.open, 'fa-plus-circle': !programa.open}"></i> {{programa.xrmName}}
</accordion-heading>
<accordion close-others="false">
<accordion-group ng-repeat="tipoDeAtencion in tiposDeAtencion" is-open="tipoDeAtencion.open">
<accordion-heading>
<i class="fa fa-lg" ng-class="{'fa-minus-circle': tipoDeAtencion.open, 'fa-plus-circle': !tipoDeAtencion.open}"></i> {{tipoDeAtencion.xrmName}}
</accordion-heading>
<div>
algo
</div>
</accordion-group>
</accordion>
</accordion-group>
</accordion>
So each level of accordion-group and its items open status will be unique.

How to debug and fix incompatible AngularJS components?

I am using angular.tree and the Accordion in UI Bootstrap. The tree properly receives events when placed outside of the accordion, but not when placed within it.
Demo here: Plunker
<p>Accordion: Click "Tree in accordion" below to show tree</p>
<div ng-controller="TestController">
<accordion close-others="true">
<accordion-group heading="Tree in accordion">
<ul ng-tree="model" multiple>
<!-- PROBLEM: doSelected() is not called -->
<li select="doSelected()">{{item.name}}</li>
</ul>
</accordion-group>
<accordion-group heading="Other">
<h1>Other</h1>
</accordion-group>
</accordion>
<hr>
<p>Another tree</p>
<ul ng-tree="model2" multiple>
<!-- doSelected2() is correctly called, see alert output -->
<li select="doSelected2()">{{item.name}}</li>
</ul>
</div>

Angular Accordion -Expand Collapsed Fails -No Event Fires

I am trying to toggle my accordion list open and close from a button but it does not work.
Any ideas as to why the event is not firing?
This code --> is-open="$parent.opened" is suppose to toggle the is-open element true anf false thereby opening and closing accordion elements
Thanks
HERE IS MY CONTROLLER
var app = angular.module('app', ['ui.bootstrap']);
app.controller('programcontroller', ['$scope',function ($scope) {
$scope.currentPage = 1;
$scope.opened = true;
}
}]);
HERE IS MY WEB PAGE BODY
<body>
<div ng-controller="programcontroller">
<button class="btn btn-default btn-xs glyphicon-plus" ng-click="togglegroup()">Expand</button>
<div data-ng-repeat="m in results">
<div class="container panel-heading">
<accordion id="accordion_{{$index+((currentPage-1)*20)+1}}" close-others="false">
<accordion-group is-open="$parent.opened">
<accordion-heading>
{{m.ALabel}} <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': opened, 'glyphicon-chevron-right': !opened}"></i>
</accordion-heading>
<p>The body of the accordion group grows to fit the contents</p>
<button class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button>
<div ng-repeat="item in items">{{item}}</div>
</accordion-group>
</accordion>
</div>
<hr />
</div>
</div>
</body>
Ok, tell me if that is what you want, on click on the button, bodies are hiding while heading are still visible
<body>
<div ng-controller="programcontroller">
<button class="btn btn-default btn-xs glyphicon-plus" ng-click="opened = !opened">Expand</button>
<div data-ng-repeat="m in results">
<div class="container panel-heading">
<accordion id="accordion_{{$index+((currentPage-1)*20)+1}}" close-others="false">
<accordion-group is-open="$parent.opened">
<accordion-heading>
{{m.ALabel}} <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': opened, 'glyphicon-chevron-right': !opened}"></i>
</accordion-heading>
<div ng-show="opened">
<p>The body of the accordion group grows to fit the contents</p>
<button class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button>
<div ng-repeat="item in items">{{item}}</div>
</div>
</accordion-group>
</accordion>
</div>
<hr />
</div>
</div>
</body>

Angularjs accordion ng-click on panel-header

In AngularJS UI Bootstrap I want to activate isopen when panel-heading is clicked, but I couldn't find a way.
In this version is activated only if you click the link.
Here's what I tried;
<accordion-group is-open="isopen">
<accordion-heading ng-click="isopen=!isopen">
I can have markup, too!
<i class="pull-right glyphicon"
ng-class="{'glyphicon-chevron-down': isopen, 'glyphicon-chevron-right': !isopen}"></i>
</accordion-heading>
This is just some content to illustrate fancy headings.
</accordion-group>
ng-click="isopen=!isopen"
This is the link I tried on Plunker
AngularJS UI Bootstrap
Thanks in advance..
EDIT:
A better solution is to move ng-click="isopen=!isopen" to the accordion-group element. This way the panel is opened/closed clicking anywhere on the panel-heading, including the edges.
<accordion close-others="oneAtATime">
<accordion-group is-open="isopen" ng-click="isopen=!isopen">
<accordion-heading >
I can have markup, too!
<i class="pull-right glyphicon"
ng-class="{'glyphicon- chevron-down': isopen, 'glyphicon-chevron-right': !isopen}">
</i>
</accordion-heading>
This is just some content to illustrate fancy headings.
</accordion-group>
</accordion>
END EDIT
enclose the content of <accordion-heading> in a <div>
<accordion close-others="oneAtATime">
<accordion-group is-open="isopen" >
<accordion-heading ng-click="isopen=!isopen">
<div>
I can have markup, too!
<i class="pull-right glyphicon"
ng-class="{'glyphicon- chevron-down': isopen, 'glyphicon-chevron-right': !isopen}">
</i>
</div>
</accordion-heading>
This is just some content to illustrate fancy headings.
</accordion-group>
</accordion>
A very simple CSS-based solution:
.panel-heading {
padding: 0;
}
.panel-title a {
display: block;
padding: 10px 15px;
}
I'm not using complex headings though - just the heading attribute as shown below, so I haven't tested it with the examples above.
<uib-accordion-group heading="Details" class="form-horizontal" is-open="true">
What you need to do is change the accordion-group.html template such that it makes the header take the ng-click event.
<div class="panel {{panelClass || 'panel-default'}}">
<div class="abc panel-heading" ng-keypress="toggleOpen($event)" ng-click="toggleOpen($event)" >
<h4 class="panel-title">
<a href tabindex="0" class="accordion-toggle" accordion-transclude="heading"><span ng-class="{'text-muted': isDisabled}">{{heading}}</span></a>
</h4>
</div>
<div class="panel-collapse collapse" collapse="!isOpen">
<div class="panel-body" ng-transclude></div>
</div>
</div>
Then in your code specify it as the template-url for the accordion-group
<accordion-group heading="Dynamic Body Content" template-url="accordion-group.html">
Example:
http://plnkr.co/edit/EXUgyNi8hrqQbh5maJUx?p=preview

How do I set model according to chosen accordion group. UI Bootstrap

I'm working on accordion using Angularjs and this directive: http://angular-ui.github.io/bootstrap/#/accordion
I have an accordion similar to this:
<accordion close-others="true">
<accordion-group heading="Static Header1">
This content is straight in the template.
</accordion-group>
<accordion-group heading="Static Header 2">
This content is straight in the template.
</accordion-group>
<accordion-group heading="Static Header 3">
This content is straight in the template.
</accordion-group>
</accordion>
I know that I can set is-open directive to specify if accordion-group is opened, but how I can pass which accordion is opened to model?
Additional question:
How can I make sure that there always one accordion opened(not multiple, and not all hidden)?
Solution that works fine, but I'm not so happy about it:
<script type="text/ng-template" id="template/accordion/accordion-group.html">
<div class="accordion-group">
<div class="accordion-heading" >
<a class="accordion-toggle no-padding" ng-click="isOpen = true" accordion-transclude="heading">{% heading %}</a>
</div>
<div class="accordion-body" collapse="!isOpen">
<div class="accordion-inner" ng-transclude></div>
</div>
</div>
</script>
<accordion close-others="true">
<accordion-group>
<accordion-heading>
<span ng-click="chosen = 'acc1'">Accordion 1</span>
</accordion-heading>
This content is straight in the template.
</accordion-group>
<accordion-group>
<accordion-heading>
<span ng-click="chosen = 'acc2'">Accordion 2</span>
</accordion-heading>
This content is straight in the template.
</accordion-group>
<accordion-group>
<accordion-heading>
<span ng-click="chosen = 'acc3'">Accordion 3</span>
</accordion-heading>
This content is straight in the template.
</accordion-group>
</accordion>
CSS style that make span full height and width:
.accordion-toggle {
padding: 0;
}
.accordion-toggle span {
display: block;
padding: 8px 15px;
}

Resources