问题
I built an md-menu
with an md-tab-group
inside, using Angular Material 2. On each md-tab
I display a different list. The behavior I'm expecting to see is that the user to be able to switch between tabs and the md-menu
to stay opened.
The thing is that the md-menu
closing on every click on one of the tabs.
<img src="/assets/images/ic-notifications.png" [mdMenuTriggerFor]="appMenu"/>
<md-menu #appMenu="mdMenu" [overlapTrigger]="false" yPosition="below" xPosition="before" class="notifications-dropdown">
<md-tab-group >
<md-tab label="My profile" id="personal">
<div class="row notification-row" *ngFor = "let notification of profile_notifications">
...
</div>
</md-tab>
<md-tab label="Favorites " id="favorite-tab" >
...
</md-tab>
</md-tab-group>
</md-menu>
How can I prevent the md-menu
from closing?
回答1:
You need to stop the mouse click propagation. You can do it like this:
<md-menu #appMenu="mdMenu" [overlapTrigger]="false" yPosition="below" xPosition="before" class="notifications-dropdown">
<md-tab-group (click)="stopClickPropagate($event)">
<md-tab label="My profile" id="personal"></md-tab>
<md-tab label="Favorites " id="favorite-tab"></md-tab>
</md-tab-group>
</md-menu>
and in your component.ts file:
stopClickPropagate(event: any){
event.stopPropagation();
event.preventDefault();
}
Link to Plunker Demo.
来源:https://stackoverflow.com/questions/45864030/md-menu-closes-after-clicking-md-tab-inside