我正在使用bootstrap和AngularJS,并且我有以下代码来制作侧边栏菜单,
<ul class="nav navbar-nav">
<li><a href="#"><span class="glyphicon glyphicon-send"></span> Link</a></li>
<li class="active"><a href="#"><span class="glyphicon glyphicon-plane"></span> Active Link</a></li>
<li><a href="#"><span class="glyphicon glyphicon-cloud"></span> Link</a></li>
<!-- Dropdown-->
<li class="panel panel-default" id="dropdown">
<a data-toggle="collapse" href="#dropdown-lvl1">
<span class="glyphicon glyphicon-user"></span> Sub Level <span class="caret"></span>
</a>
<!-- Dropdown level 1 -->
<div id="dropdown-lvl1" class="panel-collapse collapse">
<div class="panel-body">
<ul class="nav navbar-nav">
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<!-- Dropdown level 2 -->
<li class="panel panel-default" id="dropdown">
<a data-toggle="collapse" href="#dropdown-lvl2">
<span class="glyphicon glyphicon-off"></span> Sub Level <span class="caret"></span>
</a>
<div id="dropdown-lvl2" class="panel-collapse collapse">
<div class="panel-body">
<ul class="nav navbar-nav">
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
</li>
<li><a href="#"><span class="glyphicon glyphicon-signal"></span> Link</a></li>
</ul>
我的问题是,当我单击子级别菜单时,它会将我重定向到localhost /#dropdown-lvl1,而不是显示div dropdown-lvl1,你知道为什么会有这种行为吗?
最佳答案
Angular使用url中的#进行路由,因为您有<a data-toggle="collapse" href="#dropdown-lvl2">
它将尝试转到该路由,以便在页面上向下滚动使用$anchorScroll