Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(COMPONENT): Programmatically open/close menu #31993

Open
Labels
P4A relatively minor issue that is not relevant to core functionsarea: material/menufeatureThis issue represents a new feature or feature request rather than a bug or bug fix
@olfek

Description

@olfek

Feature Description

feat(COMPONENT): Programmatically open/close menu

When the menu is clicked, it opens right away.

I want to handle the click event and programmatically open the menu after doing another operation.

My workaround at present:

<buttonmatButton(click)="listData(dataMenu, $event)"#dataMenuBtn>List Data</button><mat-menu#dataMenu>    @for (item of data; track item)    {<buttonmat-menu-item>{{ item.text }}</button>    }</mat-menu>
@ViewChild('dataMenuBtn',{read:ViewContainerRef})privatereadonlydataMenuBtnViewContainerRef!:ViewContainerRef;@ViewChild('dataMenuBtn',{read:ElementRef})privatereadonlydataMenuBtnElementRef!:ElementRef;privatedataMenuTrigger!:MatMenuTrigger;protecteddata:{ text:string}[]=[];protectedasynclistData(dataMenu:MatMenu,$event:MouseEvent):Promise<void>{constmenuTrigger=this.dataMenuTrigger??(this.dataMenuTrigger=runInInjectionContext(Injector.create({providers:[{provide:ElementRef,useValue:this.dataMenuBtnElementRef},{provide:ViewContainerRef,useValue:this.dataMenuBtnViewContainerRef}],parent:this.injector// `Injector` via DI.}),()=>newMatMenuTrigger()));menuTrigger.menu=dataMenu;constresult=awaitfetch(`/api/...`);this.data=awaitresult.json()astypeofthis.data;menuTrigger.openMenu();}

Use Case

Load data inside menu on click

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: material/menufeatureThis issue represents a new feature or feature request rather than a bug or bug fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp