@@ -6,12 +6,12 @@ By itself, the `<mat-menu>` element does not render anything. The menu is attach
66via application of the ` matMenuTriggerFor ` directive:
77``` html
88<mat-menu #appMenu =" matMenu" >
9- <button mat-menu-item > Settings </button >
10- <button mat-menu-item > Help </button >
9+ <button mat-menu-item >Settings</button >
10+ <button mat-menu-item >Help</button >
1111</mat-menu >
1212
1313<button mat-icon-button [matMenuTriggerFor] =" appMenu" >
14- <mat-icon >more_vert</mat-icon >
14+ <mat-icon >more_vert</mat-icon >
1515</button >
1616```
1717
@@ -36,16 +36,16 @@ Menus support displaying `mat-icon` elements before the menu item text.
3636``` html
3737<mat-menu #menu =" matMenu" >
3838 <button mat-menu-item >
39- <mat-icon > dialpad </mat-icon >
40- <span > Redial </span >
39+ <mat-icon >dialpad</mat-icon >
40+ <span >Redial</span >
4141 </button >
4242 <button mat-menu-item disabled >
43- <mat-icon > voicemail </mat-icon >
44- <span > Check voicemail </span >
43+ <mat-icon >voicemail</mat-icon >
44+ <span >Check voicemail</span >
4545 </button >
4646 <button mat-menu-item >
47- <mat-icon > notifications_off </mat-icon >
48- <span > Disable alerts </span >
47+ <mat-icon >notifications_off</mat-icon >
48+ <span >Disable alerts</span >
4949 </button >
5050</mat-menu >
5151```
@@ -59,8 +59,8 @@ The position can be changed using the `xPosition` (`before | after`) and `yPosit
5959
6060``` html
6161<mat-menu #appMenu =" matMenu" yPosition =" above" >
62- <button mat-menu-item > Settings </button >
63- <button mat-menu-item > Help </button >
62+ <button mat-menu-item >Settings</button >
63+ <button mat-menu-item >Help</button >
6464</mat-menu >
6565
6666<button mat-icon-button [matMenuTriggerFor] =" appMenu" >
@@ -93,6 +93,46 @@ that should trigger the sub-menu:
9393
9494<!-- example(nested-menu) -->
9595
96+ ### Lazy rendering
97+ By default, the menu content will be initialized even when the panel is closed. To defer
98+ initialization until the menu is open, the content can be provided as an ` ng-template `
99+ with the ` matMenuContent ` attribute:
100+
101+ ``` html
102+ <mat-menu #appMenu =" matMenu" >
103+ <ng-template matMenuContent >
104+ <button mat-menu-item >Settings</button >
105+ <button mat-menu-item >Help</button >
106+ </ng-template >
107+ </mat-menu >
108+
109+ <button mat-icon-button [matMenuTriggerFor] =" appMenu" >
110+ <mat-icon >more_vert</mat-icon >
111+ </button >
112+ ```
113+
114+ ### Passing in data to a menu
115+ When using lazy rendering, additional context data can be passed to the menu panel via
116+ the ` matMenuTriggerData ` input. This allows for a single menu instance to be rendered
117+ with a different set of data, depending on the trigger that opened it:
118+
119+ ``` html
120+ <mat-menu #appMenu =" matMenu" let-user =" user" >
121+ <ng-template matMenuContent >
122+ <button mat-menu-item >Settings</button >
123+ <button mat-menu-item >Log off {{name}}</button >
124+ </ng-template >
125+ </mat-menu >
126+
127+ <button mat-icon-button [matMenuTriggerFor] =" appMenu" [matMenuTriggerData] =" {name: 'Sally'}" >
128+ <mat-icon >more_vert</mat-icon >
129+ </button >
130+
131+ <button mat-icon-button [matMenuTriggerFor] =" appMenu" [matMenuTriggerData] =" {name: 'Bob'}" >
132+ <mat-icon >more_vert</mat-icon >
133+ </button >
134+ ```
135+
96136### Keyboard interaction
97137- <kbd >DOWN_ARROW</kbd >: Focuses the next menu item
98138- <kbd >UP_ARROW</kbd >: Focuses previous menu item
0 commit comments