Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using bootstrap accordion on an angularjs page

I am having an issue when I try to run the following code in an AngularJS page.

      <div class='panel-group' id=accordion'>
        <div class="panel panel-default">
          <h4 class="panel-title">
            <a data-toggle='collapse' data-parent='#accordion' href='#collapseOne'>foo</a>
          </h4>
          <div id='collapseOne' class='panel-collapse collapse'>
            <div class='panel-body'>
              <p>foo</p>
            </div>
          </div>
        </div>
      </div>

The code is correct, but since Angular uses # as an anchor for the routine, when I click to toggle my accordion, it redirects me to my homepage. Is there any way I could prevent this ?

ps: I know there is a library ui-bootstrap for angularjs with a directive to handle accordion, I just would like to know if there is a way to solve my issue without it :).

like image 938
Scipion Avatar asked Aug 24 '26 05:08

Scipion


1 Answers

If you want a quick slightly hacky way without writing your own directive or using BootstrapUI, you could perhaps bypass the bootstrap jQuery way of toggling the accordion and put angular directives into the markup instead:

<div class='panel-group' id=accordion'>
    <div class="panel panel-default">
        <h4 class="panel-title">
            <a data-ng-click="accordion1 = !accordion1">foo</a>
        </h4>
        <div data-ng-show="accordion1">
            <div class='panel-body'>
                <p>foo</p>
            </div>
        </div>
    </div>
</div>

Might need some slight css if the removed collapse classes from the body wrapper do anything apart from just show/hide

like image 113
Starscream1984 Avatar answered Aug 26 '26 19:08

Starscream1984



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!