防止关闭md菜单栏以进行ng-click

时间:2016-03-10 19:02:24

标签: angularjs

我有md-menu-bar这样:

<md-menu-bar>
    <md-menu>
        <button ng-click="$mdOpenMenu()">
            <md-menu-content>
                <md-menu-item>
                    <md-button ng-click="doSomething()">...</md-button>
                </md-menu-item>
                <md-menu-item>
                    <md-button ng-click="doSomethingButDoNotClose()">...</md-button>
                </md-menu-item>

        </button>
    </md-menu>
<md-menu-bar>

我需要您点击md-buttondoSomethingButDoNotClose菜单未关闭,我该如何处理?

1 个答案:

答案 0 :(得分:0)

将事件对象传递给您的函数,如下所示:

<md-button ng-click="doSomethingButDoNotClose($event)">...</md-button>

...并在doSomethingButDoNotClose函数中使用它:

$scope.doSomethingButDoNotClose = function (event) {
    ...
    event.preventDefault();
}

preventDefault函数会停止发生默认事件操作,并且(希望)会阻止菜单关闭(我还没有使用md-button进行测试)。