解决方法
如果您在单击bootstrap下拉菜单的任何选项时更新路线,那么您可以只注意路线更改事件:
<a class="dropdown-toggle"> Click me for a dropdown,yo! </a> <ul class="dropdown-menu"> <li ng-repeat="choice in items" class="ng-scope"> <a class="ng-binding">The first choice!</a> </li><li ng-repeat="choice in items" class="ng-scope"> <a class="ng-binding">And another choice for you.</a> </li><li ng-repeat="choice in items" class="ng-scope"> <a class="ng-binding">but wait! A third!</a> </li> </ul> $scope.$on('$routeUpdate',function(scope,next,current) { $('html').trigger('click'); });
上面的方法是有效的,但绝对不需要在每次路由更改时抓取html元素(因为它会导致重排),所以最好把它放在指令中,如下所示:
<html hide-dropdown> angular.module('App',[]). directive('hideDropdown',function() { return { restrict: 'A',link: function(scope,element) { scope.$on('$routeUpdate',current) { element.trigger('click'); }); } } });