Angularjs - ng-click and $event.stopPropagation disable twitter bootstrap context menu

我只是一个虾纸丫 提交于 2019-12-11 22:55:56

问题


Hey guys so I am trying to use $event.stopPropagation because I have many different clicks in one container that need to be independent and I handle them using $event.stopPropagation as well, but when it comes to bootstrap, I cannot for some reason make it work . The context menu click is detected as actual ng-click on the whole container. How can I make the twitter bootstrap context menu act as if it had $event.stopPropagation?

Here is a fiddle http://jsfiddle.net/GeorgiAngelov/tJY2s/

I even tried adding an ng-click event that will trigger the href='#' but it still does not work. jsFiddle with ng-click to replace the href='#' http://jsfiddle.net/GeorgiAngelov/tJY2s/1/

<div ng-app='project' ng-click="myClick()">
    <div ng-controller="MainController" ng-click="myClick($event)">
        <div>
            <div class="header" >
                dasdasdasdasd
            </div>
        </div>

        <div class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu</a>
            <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
                <li><a tabindex="-1" ng-click="">One</a></li>
                <li><a tabindex="-1" ng-click="">Two</a></li>
            </ul>
        </div>
    </div>
</div>

回答1:


Bootstrap does not use Angular mechanism, namely $apply/$digest cycle, to handle events. You might want to check out the angular bootstrap project: http://angular-ui.github.io/bootstrap.



来源:https://stackoverflow.com/questions/17624061/angularjs-ng-click-and-event-stoppropagation-disable-twitter-bootstrap-contex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!