使用bootstrap时关闭$ routeprovider

时间:2014-05-16 14:56:19

标签: javascript angularjs twitter-bootstrap

我有一些正常的routeprovider代码,但在我的HTML的某个部分我有一些twitter bootstrap展开/折叠部分。点击它们会触发routeprovider,我不想这样做。有办法防止这种情况吗?

myApp.config(function ($routeProvider, $locationProvider) {

  $routeProvider
    .when('/', {
      templateUrl: 'login.html',
      controller: 'mainController'
    })
    .when('/projects', {
      templateUrl: 'project.html',
      controller: 'projectController'
    });

  $locationProvider.html5Mode(true);
});

HTML的一部分

<div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                              Open Projects
                          </a>
                      </h4>
                  </div>
                  <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <table id="openProjectTable" class="table">
                            <tr><th>Project</th><th>Source</th><th>Target</th></tr>
                        </table>
                    </div>
                </div>
            </div>

1 个答案:

答案 0 :(得分:1)

最简单的解决方案是使用数据目标而不是 href

<a data-toggle="collapse" data-parent="#accordion" data-target="#collapseOne">
  Open Projects
</a>

演示: http://plnkr.co/edit/OYEeUd6hAJE0hBBJOrp7?p=preview