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

前端 未结 4 649
再見小時候
再見小時候 2020-12-14 12:07

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

<
相关标签:
4条回答
  • 2020-12-14 12:26

    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;"

    0 讨论(0)
  • 2020-12-14 12:37

    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.

    0 讨论(0)
  • 2020-12-14 12:39

    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>
    
    0 讨论(0)
  • 2020-12-14 12:42

    I was having an issue using href and data-target together, so if you are using this in an application I'd recommend specifying one or the other but not both.

    When I used both, I'd get redirected to my login page as soon as I clicked on it. With one or the other specified it worked fine, but not with both.

    0 讨论(0)
提交回复
热议问题