Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS with bootstrap 3 accordion not working when included via ng-view

The problem is the following: As soon as I use the accordion in a view that is loaded in the ng-view directive, the accordion title clicks dont work correctly anymore

http://plnkr.co/edit/KGwuqDIb7I5NrYCtPOPk?p=preview

If the accordion is use in the page itself with no ng-view, the accordion works perfectly

http://plnkr.co/edit/8dY7JU1kxjZ2jAKmMIrP?p=preview

Any clue to what Im missing?

like image 726
Stephan Grobler Avatar asked Sep 14 '13 16:09

Stephan Grobler


3 Answers

Actually, there might be a simpler solution.

You can just make sure that the links don't propagate the URL change.

Add to the a tag onclick="return false;"

like image 97
mfloryan Avatar answered Nov 19 '22 15:11

mfloryan


The problem is that Bootstrap appends #according_name within a a tag. This triggers a AngularJS routing and due to route change test.html is loaded again on every click on accordian link.

Your options are to try to configure $locationProvider to use HTML5 mode with hashbag if it works

$locationProvider.html5Mode(true).hashPrefix('!');

See some documentation here

Other would be to use angular-ui component but it has been not ported to support version 3 of bootstrap.

like image 23
Chandermani Avatar answered Nov 19 '22 16:11

Chandermani


You can empty the href="" and use

data-target="#collapse" instead, this worked for me

i.e

<a data-toggle="collapse" data-parent="#accordion" href="" 
data-target="#collapse1">Collapsible Group 1</a>
like image 15
Sreekanth Karini Avatar answered Nov 19 '22 14:11

Sreekanth Karini