Passing data to mat-menuAngular2 consuming service that makes HTTP call in component methodMat-menu in for loop: performance issuesHow to attach matMenuTriggerFor dynamically to DOM element in Angular material menu?Uncaught Error: Template parse errors: 'app-message-menu' is not a known element. Angular 4Trigger mat-menu in child component from parent componentAngular 6 'mat-button-toggle' is not a known elementAngular 6: mat-toolbar and mat-toolbar-row in footer (shared) component is not displaying properly (but without any error)?Angular. How to pass dynamic conponent to mat-table cell?Material mat-radio-button name attribute for simple form POSTIs there a way to trigger a mat-dialog component with #mdDialog Service?

Spacing setting of math mode

Using "Kollege" as "university friend"?

How important is a good quality camera for good photography?

A planet illuminated by a black hole?

Company messed up with patent and now a lawyer is coming after me

Extrapolation v. Interpolation

Is Grandpa Irrational? Another Grandpa Mystery

Closet Wall, is it Load Bearing?

Why is chess failing to attract big name sponsors?

Is it normal practice to screen share with a client?

Why is a dedicated QA team member necessary?

What is "ass door"?

How do professional electronic musicians/sound engineers combat listening fatigue?

How did C64 games handle music during gameplay?

How were the LM astronauts supported during the moon landing and ascent? What were the max G's on them during these phases?

Book about young girl who ends up in space after apocolypse

This message is flooding my syslog, how to find where it comes from?

USA: Can a witness take the 5th to avoid perjury?

How can I receive packages while in France?

How can I tell if there was a power cut while I was out?

How can I stop myself from micromanaging other PCs' actions?

How do campaign rallies gain candidates votes?

Where is this photo of a group of hikers taken? Is it really in the Ural?

What is the life span of a Flerken?



Passing data to mat-menu


Angular2 consuming service that makes HTTP call in component methodMat-menu in for loop: performance issuesHow to attach matMenuTriggerFor dynamically to DOM element in Angular material menu?Uncaught Error: Template parse errors: 'app-message-menu' is not a known element. Angular 4Trigger mat-menu in child component from parent componentAngular 6 'mat-button-toggle' is not a known elementAngular 6: mat-toolbar and mat-toolbar-row in footer (shared) component is not displaying properly (but without any error)?Angular. How to pass dynamic conponent to mat-table cell?Material mat-radio-button name attribute for simple form POSTIs there a way to trigger a mat-dialog component with #mdDialog Service?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















My 'awesome' menu:



<mat-menu #appMenu="matMenu">
<ng-template matMenuContent let-myobject="myobject">
<button mat-menu-item>Delete myobject.name</button>
<button mat-menu-item>Smth else</button>
</ng-template>
</mat-menu>

<button mat-icon-button [matMenuTriggerFor]="appMenu" [matMenuTriggerData]="myobject: myobject">
<mat-icon>more_vert</mat-icon>
</button>


First question is if it is ok? Wrote this following documentation but let-myobject="myobject" and myobject: myobject looks like overhead (?)



Second question is if I want to calculate some data based on myobject - how I do that? I want it to be calculated just before menu is opened.



[matMenuTriggerData]="getData(myobject)" - cant make this or similar work



<ng-template matMenuContent let-data="getData(myobject)"> - cant make this or similar work either



I know that I can replace ng-template with component here, but then for e.g. 10 menu items I will need to do 10 outputs in this component. (? or I cant...)










share|improve this question
























  • Sometimes angular syntax does seem overhead :) However, you should avoid passing a method to any input properties as they will get called for every change detection affecting the performance. What you can do here is listen to the menuOpened event of the MatMenuTrigger directive and then calculate in the handler function and set the right matMenuTriggerData reference.

    – ashish.gd
    Mar 26 at 16:20

















1















My 'awesome' menu:



<mat-menu #appMenu="matMenu">
<ng-template matMenuContent let-myobject="myobject">
<button mat-menu-item>Delete myobject.name</button>
<button mat-menu-item>Smth else</button>
</ng-template>
</mat-menu>

<button mat-icon-button [matMenuTriggerFor]="appMenu" [matMenuTriggerData]="myobject: myobject">
<mat-icon>more_vert</mat-icon>
</button>


First question is if it is ok? Wrote this following documentation but let-myobject="myobject" and myobject: myobject looks like overhead (?)



Second question is if I want to calculate some data based on myobject - how I do that? I want it to be calculated just before menu is opened.



[matMenuTriggerData]="getData(myobject)" - cant make this or similar work



<ng-template matMenuContent let-data="getData(myobject)"> - cant make this or similar work either



I know that I can replace ng-template with component here, but then for e.g. 10 menu items I will need to do 10 outputs in this component. (? or I cant...)










share|improve this question
























  • Sometimes angular syntax does seem overhead :) However, you should avoid passing a method to any input properties as they will get called for every change detection affecting the performance. What you can do here is listen to the menuOpened event of the MatMenuTrigger directive and then calculate in the handler function and set the right matMenuTriggerData reference.

    – ashish.gd
    Mar 26 at 16:20













1












1








1


1






My 'awesome' menu:



<mat-menu #appMenu="matMenu">
<ng-template matMenuContent let-myobject="myobject">
<button mat-menu-item>Delete myobject.name</button>
<button mat-menu-item>Smth else</button>
</ng-template>
</mat-menu>

<button mat-icon-button [matMenuTriggerFor]="appMenu" [matMenuTriggerData]="myobject: myobject">
<mat-icon>more_vert</mat-icon>
</button>


First question is if it is ok? Wrote this following documentation but let-myobject="myobject" and myobject: myobject looks like overhead (?)



Second question is if I want to calculate some data based on myobject - how I do that? I want it to be calculated just before menu is opened.



[matMenuTriggerData]="getData(myobject)" - cant make this or similar work



<ng-template matMenuContent let-data="getData(myobject)"> - cant make this or similar work either



I know that I can replace ng-template with component here, but then for e.g. 10 menu items I will need to do 10 outputs in this component. (? or I cant...)










share|improve this question
















My 'awesome' menu:



<mat-menu #appMenu="matMenu">
<ng-template matMenuContent let-myobject="myobject">
<button mat-menu-item>Delete myobject.name</button>
<button mat-menu-item>Smth else</button>
</ng-template>
</mat-menu>

<button mat-icon-button [matMenuTriggerFor]="appMenu" [matMenuTriggerData]="myobject: myobject">
<mat-icon>more_vert</mat-icon>
</button>


First question is if it is ok? Wrote this following documentation but let-myobject="myobject" and myobject: myobject looks like overhead (?)



Second question is if I want to calculate some data based on myobject - how I do that? I want it to be calculated just before menu is opened.



[matMenuTriggerData]="getData(myobject)" - cant make this or similar work



<ng-template matMenuContent let-data="getData(myobject)"> - cant make this or similar work either



I know that I can replace ng-template with component here, but then for e.g. 10 menu items I will need to do 10 outputs in this component. (? or I cant...)







angular angular-material






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 16:09







Petr Averyanov

















asked Mar 26 at 16:02









Petr AveryanovPetr Averyanov

7,2741 gold badge13 silver badges23 bronze badges




7,2741 gold badge13 silver badges23 bronze badges












  • Sometimes angular syntax does seem overhead :) However, you should avoid passing a method to any input properties as they will get called for every change detection affecting the performance. What you can do here is listen to the menuOpened event of the MatMenuTrigger directive and then calculate in the handler function and set the right matMenuTriggerData reference.

    – ashish.gd
    Mar 26 at 16:20

















  • Sometimes angular syntax does seem overhead :) However, you should avoid passing a method to any input properties as they will get called for every change detection affecting the performance. What you can do here is listen to the menuOpened event of the MatMenuTrigger directive and then calculate in the handler function and set the right matMenuTriggerData reference.

    – ashish.gd
    Mar 26 at 16:20
















Sometimes angular syntax does seem overhead :) However, you should avoid passing a method to any input properties as they will get called for every change detection affecting the performance. What you can do here is listen to the menuOpened event of the MatMenuTrigger directive and then calculate in the handler function and set the right matMenuTriggerData reference.

– ashish.gd
Mar 26 at 16:20





Sometimes angular syntax does seem overhead :) However, you should avoid passing a method to any input properties as they will get called for every change detection affecting the performance. What you can do here is listen to the menuOpened event of the MatMenuTrigger directive and then calculate in the handler function and set the right matMenuTriggerData reference.

– ashish.gd
Mar 26 at 16:20












1 Answer
1






active

oldest

votes


















3














You can certainly pass an object to a mat-menu by using the matMenuTriggerData directive. This object can contain a single value, another object, or even an array of values or objects. Here's how I solved it:



My challenge was this: I wanted to dynamically build a list of menu items (mat-menu-item) based on the contents of an array. How did I manage to pass that array of objects to my mat-menu?



In your component class you can define the array of objects:



export class MyComponent implements OnInit 
menuData: any;

ngOnInit()
this.menuData =
menuItems: [
code: '1', name: 'first',
code: '2', name: 'second'
]
;




Notice that the object I will pass to the matMenuTriggerData directive of the button that opens the mat-menu content, is the data member called menuData. This member has only one property which is an array of objects. These represent the actual menu items I want to display in my template. The template is shown below:



<mat-menu #app-menu="matMenu">
<ng-template matMenuContent let-aliasMenuItems="menuItems">
<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>
</ng-template>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="app-menu" [matMenuTriggerData]="menuData">
<mat-icon>more_vert</mat-icon>
</button>


Let me explain what is going on in the template: The button defined in the bottom of the template has been linked to the mat-menu called 'app-menu'. This is done by typing [matMenuTriggerFor]="app-menu".



The next thing we do is passing the component's member data to the mat-menu through this directive: [matMenuTriggerData]="menuData". The mat-menu instance that we named app-menu can now grab the content of that member data.



As you can see, the <ng-template> accesses the property of 'menuData' that we have named 'menuItems'. The <ng-template> adds a pointer or alias to that property (called aliasMenuItems), like this: <ng-template let-aliasMenuItems="menuItems">. Now we are able to loop through our defined array of menu items inside the <ng-template>.



In my example, I create a <button mat-menu-item></button> element for each menu item object that exists in my component's menuData.menuItems array, like this:



<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>


I hope you find this answer useful.






share|improve this answer























  • Just wanted to mention that you can also call a method on your component that returns an object containing the same array: [matMenuTriggerData]="getMenuData()".

    – Ittit
    May 22 at 12:47











  • Giving you credit for such long answer... But seems like you did not get my problem -- imagine you have 100 matMenuTriggerFor on page for same menu -- how to get this working without creating 100 objects for each?

    – Petr Averyanov
    May 22 at 13:28











  • So you want to re-use that single mat-menu element inside your template, and have it receive separate sets of data (menu items) from several different buttons? If you click on button 1, you want to use the matMenuTriggerData attribute to send one list of menu items to the mat-menu element, and by using button 2, you send a different list of menu items to it? In that case I would put the mat-menu inside a separate component which can receive an array of menu items via an @Input property. Then you could use it like this in your template: <my-menu [menuItems]="listOfItemsFromModel"></my-menu>.

    – Ittit
    May 23 at 12:09











  • Please let me know if you want me to show you an example of how to do what I suggest in my previous comment. I'll gladly update my suggestion above. :-)

    – Ittit
    May 23 at 12:17










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361484%2fpassing-data-to-mat-menu%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














You can certainly pass an object to a mat-menu by using the matMenuTriggerData directive. This object can contain a single value, another object, or even an array of values or objects. Here's how I solved it:



My challenge was this: I wanted to dynamically build a list of menu items (mat-menu-item) based on the contents of an array. How did I manage to pass that array of objects to my mat-menu?



In your component class you can define the array of objects:



export class MyComponent implements OnInit 
menuData: any;

ngOnInit()
this.menuData =
menuItems: [
code: '1', name: 'first',
code: '2', name: 'second'
]
;




Notice that the object I will pass to the matMenuTriggerData directive of the button that opens the mat-menu content, is the data member called menuData. This member has only one property which is an array of objects. These represent the actual menu items I want to display in my template. The template is shown below:



<mat-menu #app-menu="matMenu">
<ng-template matMenuContent let-aliasMenuItems="menuItems">
<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>
</ng-template>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="app-menu" [matMenuTriggerData]="menuData">
<mat-icon>more_vert</mat-icon>
</button>


Let me explain what is going on in the template: The button defined in the bottom of the template has been linked to the mat-menu called 'app-menu'. This is done by typing [matMenuTriggerFor]="app-menu".



The next thing we do is passing the component's member data to the mat-menu through this directive: [matMenuTriggerData]="menuData". The mat-menu instance that we named app-menu can now grab the content of that member data.



As you can see, the <ng-template> accesses the property of 'menuData' that we have named 'menuItems'. The <ng-template> adds a pointer or alias to that property (called aliasMenuItems), like this: <ng-template let-aliasMenuItems="menuItems">. Now we are able to loop through our defined array of menu items inside the <ng-template>.



In my example, I create a <button mat-menu-item></button> element for each menu item object that exists in my component's menuData.menuItems array, like this:



<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>


I hope you find this answer useful.






share|improve this answer























  • Just wanted to mention that you can also call a method on your component that returns an object containing the same array: [matMenuTriggerData]="getMenuData()".

    – Ittit
    May 22 at 12:47











  • Giving you credit for such long answer... But seems like you did not get my problem -- imagine you have 100 matMenuTriggerFor on page for same menu -- how to get this working without creating 100 objects for each?

    – Petr Averyanov
    May 22 at 13:28











  • So you want to re-use that single mat-menu element inside your template, and have it receive separate sets of data (menu items) from several different buttons? If you click on button 1, you want to use the matMenuTriggerData attribute to send one list of menu items to the mat-menu element, and by using button 2, you send a different list of menu items to it? In that case I would put the mat-menu inside a separate component which can receive an array of menu items via an @Input property. Then you could use it like this in your template: <my-menu [menuItems]="listOfItemsFromModel"></my-menu>.

    – Ittit
    May 23 at 12:09











  • Please let me know if you want me to show you an example of how to do what I suggest in my previous comment. I'll gladly update my suggestion above. :-)

    – Ittit
    May 23 at 12:17















3














You can certainly pass an object to a mat-menu by using the matMenuTriggerData directive. This object can contain a single value, another object, or even an array of values or objects. Here's how I solved it:



My challenge was this: I wanted to dynamically build a list of menu items (mat-menu-item) based on the contents of an array. How did I manage to pass that array of objects to my mat-menu?



In your component class you can define the array of objects:



export class MyComponent implements OnInit 
menuData: any;

ngOnInit()
this.menuData =
menuItems: [
code: '1', name: 'first',
code: '2', name: 'second'
]
;




Notice that the object I will pass to the matMenuTriggerData directive of the button that opens the mat-menu content, is the data member called menuData. This member has only one property which is an array of objects. These represent the actual menu items I want to display in my template. The template is shown below:



<mat-menu #app-menu="matMenu">
<ng-template matMenuContent let-aliasMenuItems="menuItems">
<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>
</ng-template>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="app-menu" [matMenuTriggerData]="menuData">
<mat-icon>more_vert</mat-icon>
</button>


Let me explain what is going on in the template: The button defined in the bottom of the template has been linked to the mat-menu called 'app-menu'. This is done by typing [matMenuTriggerFor]="app-menu".



The next thing we do is passing the component's member data to the mat-menu through this directive: [matMenuTriggerData]="menuData". The mat-menu instance that we named app-menu can now grab the content of that member data.



As you can see, the <ng-template> accesses the property of 'menuData' that we have named 'menuItems'. The <ng-template> adds a pointer or alias to that property (called aliasMenuItems), like this: <ng-template let-aliasMenuItems="menuItems">. Now we are able to loop through our defined array of menu items inside the <ng-template>.



In my example, I create a <button mat-menu-item></button> element for each menu item object that exists in my component's menuData.menuItems array, like this:



<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>


I hope you find this answer useful.






share|improve this answer























  • Just wanted to mention that you can also call a method on your component that returns an object containing the same array: [matMenuTriggerData]="getMenuData()".

    – Ittit
    May 22 at 12:47











  • Giving you credit for such long answer... But seems like you did not get my problem -- imagine you have 100 matMenuTriggerFor on page for same menu -- how to get this working without creating 100 objects for each?

    – Petr Averyanov
    May 22 at 13:28











  • So you want to re-use that single mat-menu element inside your template, and have it receive separate sets of data (menu items) from several different buttons? If you click on button 1, you want to use the matMenuTriggerData attribute to send one list of menu items to the mat-menu element, and by using button 2, you send a different list of menu items to it? In that case I would put the mat-menu inside a separate component which can receive an array of menu items via an @Input property. Then you could use it like this in your template: <my-menu [menuItems]="listOfItemsFromModel"></my-menu>.

    – Ittit
    May 23 at 12:09











  • Please let me know if you want me to show you an example of how to do what I suggest in my previous comment. I'll gladly update my suggestion above. :-)

    – Ittit
    May 23 at 12:17













3












3








3







You can certainly pass an object to a mat-menu by using the matMenuTriggerData directive. This object can contain a single value, another object, or even an array of values or objects. Here's how I solved it:



My challenge was this: I wanted to dynamically build a list of menu items (mat-menu-item) based on the contents of an array. How did I manage to pass that array of objects to my mat-menu?



In your component class you can define the array of objects:



export class MyComponent implements OnInit 
menuData: any;

ngOnInit()
this.menuData =
menuItems: [
code: '1', name: 'first',
code: '2', name: 'second'
]
;




Notice that the object I will pass to the matMenuTriggerData directive of the button that opens the mat-menu content, is the data member called menuData. This member has only one property which is an array of objects. These represent the actual menu items I want to display in my template. The template is shown below:



<mat-menu #app-menu="matMenu">
<ng-template matMenuContent let-aliasMenuItems="menuItems">
<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>
</ng-template>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="app-menu" [matMenuTriggerData]="menuData">
<mat-icon>more_vert</mat-icon>
</button>


Let me explain what is going on in the template: The button defined in the bottom of the template has been linked to the mat-menu called 'app-menu'. This is done by typing [matMenuTriggerFor]="app-menu".



The next thing we do is passing the component's member data to the mat-menu through this directive: [matMenuTriggerData]="menuData". The mat-menu instance that we named app-menu can now grab the content of that member data.



As you can see, the <ng-template> accesses the property of 'menuData' that we have named 'menuItems'. The <ng-template> adds a pointer or alias to that property (called aliasMenuItems), like this: <ng-template let-aliasMenuItems="menuItems">. Now we are able to loop through our defined array of menu items inside the <ng-template>.



In my example, I create a <button mat-menu-item></button> element for each menu item object that exists in my component's menuData.menuItems array, like this:



<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>


I hope you find this answer useful.






share|improve this answer













You can certainly pass an object to a mat-menu by using the matMenuTriggerData directive. This object can contain a single value, another object, or even an array of values or objects. Here's how I solved it:



My challenge was this: I wanted to dynamically build a list of menu items (mat-menu-item) based on the contents of an array. How did I manage to pass that array of objects to my mat-menu?



In your component class you can define the array of objects:



export class MyComponent implements OnInit 
menuData: any;

ngOnInit()
this.menuData =
menuItems: [
code: '1', name: 'first',
code: '2', name: 'second'
]
;




Notice that the object I will pass to the matMenuTriggerData directive of the button that opens the mat-menu content, is the data member called menuData. This member has only one property which is an array of objects. These represent the actual menu items I want to display in my template. The template is shown below:



<mat-menu #app-menu="matMenu">
<ng-template matMenuContent let-aliasMenuItems="menuItems">
<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>
</ng-template>
</mat-menu>
<button mat-icon-button [matMenuTriggerFor]="app-menu" [matMenuTriggerData]="menuData">
<mat-icon>more_vert</mat-icon>
</button>


Let me explain what is going on in the template: The button defined in the bottom of the template has been linked to the mat-menu called 'app-menu'. This is done by typing [matMenuTriggerFor]="app-menu".



The next thing we do is passing the component's member data to the mat-menu through this directive: [matMenuTriggerData]="menuData". The mat-menu instance that we named app-menu can now grab the content of that member data.



As you can see, the <ng-template> accesses the property of 'menuData' that we have named 'menuItems'. The <ng-template> adds a pointer or alias to that property (called aliasMenuItems), like this: <ng-template let-aliasMenuItems="menuItems">. Now we are able to loop through our defined array of menu items inside the <ng-template>.



In my example, I create a <button mat-menu-item></button> element for each menu item object that exists in my component's menuData.menuItems array, like this:



<button mat-menu-item *ngFor="let item of aliasMenuItems">
Item item.code: item.name
</button>


I hope you find this answer useful.







share|improve this answer












share|improve this answer



share|improve this answer










answered May 22 at 12:27









IttitIttit

315 bronze badges




315 bronze badges












  • Just wanted to mention that you can also call a method on your component that returns an object containing the same array: [matMenuTriggerData]="getMenuData()".

    – Ittit
    May 22 at 12:47











  • Giving you credit for such long answer... But seems like you did not get my problem -- imagine you have 100 matMenuTriggerFor on page for same menu -- how to get this working without creating 100 objects for each?

    – Petr Averyanov
    May 22 at 13:28











  • So you want to re-use that single mat-menu element inside your template, and have it receive separate sets of data (menu items) from several different buttons? If you click on button 1, you want to use the matMenuTriggerData attribute to send one list of menu items to the mat-menu element, and by using button 2, you send a different list of menu items to it? In that case I would put the mat-menu inside a separate component which can receive an array of menu items via an @Input property. Then you could use it like this in your template: <my-menu [menuItems]="listOfItemsFromModel"></my-menu>.

    – Ittit
    May 23 at 12:09











  • Please let me know if you want me to show you an example of how to do what I suggest in my previous comment. I'll gladly update my suggestion above. :-)

    – Ittit
    May 23 at 12:17

















  • Just wanted to mention that you can also call a method on your component that returns an object containing the same array: [matMenuTriggerData]="getMenuData()".

    – Ittit
    May 22 at 12:47











  • Giving you credit for such long answer... But seems like you did not get my problem -- imagine you have 100 matMenuTriggerFor on page for same menu -- how to get this working without creating 100 objects for each?

    – Petr Averyanov
    May 22 at 13:28











  • So you want to re-use that single mat-menu element inside your template, and have it receive separate sets of data (menu items) from several different buttons? If you click on button 1, you want to use the matMenuTriggerData attribute to send one list of menu items to the mat-menu element, and by using button 2, you send a different list of menu items to it? In that case I would put the mat-menu inside a separate component which can receive an array of menu items via an @Input property. Then you could use it like this in your template: <my-menu [menuItems]="listOfItemsFromModel"></my-menu>.

    – Ittit
    May 23 at 12:09











  • Please let me know if you want me to show you an example of how to do what I suggest in my previous comment. I'll gladly update my suggestion above. :-)

    – Ittit
    May 23 at 12:17
















Just wanted to mention that you can also call a method on your component that returns an object containing the same array: [matMenuTriggerData]="getMenuData()".

– Ittit
May 22 at 12:47





Just wanted to mention that you can also call a method on your component that returns an object containing the same array: [matMenuTriggerData]="getMenuData()".

– Ittit
May 22 at 12:47













Giving you credit for such long answer... But seems like you did not get my problem -- imagine you have 100 matMenuTriggerFor on page for same menu -- how to get this working without creating 100 objects for each?

– Petr Averyanov
May 22 at 13:28





Giving you credit for such long answer... But seems like you did not get my problem -- imagine you have 100 matMenuTriggerFor on page for same menu -- how to get this working without creating 100 objects for each?

– Petr Averyanov
May 22 at 13:28













So you want to re-use that single mat-menu element inside your template, and have it receive separate sets of data (menu items) from several different buttons? If you click on button 1, you want to use the matMenuTriggerData attribute to send one list of menu items to the mat-menu element, and by using button 2, you send a different list of menu items to it? In that case I would put the mat-menu inside a separate component which can receive an array of menu items via an @Input property. Then you could use it like this in your template: <my-menu [menuItems]="listOfItemsFromModel"></my-menu>.

– Ittit
May 23 at 12:09





So you want to re-use that single mat-menu element inside your template, and have it receive separate sets of data (menu items) from several different buttons? If you click on button 1, you want to use the matMenuTriggerData attribute to send one list of menu items to the mat-menu element, and by using button 2, you send a different list of menu items to it? In that case I would put the mat-menu inside a separate component which can receive an array of menu items via an @Input property. Then you could use it like this in your template: <my-menu [menuItems]="listOfItemsFromModel"></my-menu>.

– Ittit
May 23 at 12:09













Please let me know if you want me to show you an example of how to do what I suggest in my previous comment. I'll gladly update my suggestion above. :-)

– Ittit
May 23 at 12:17





Please let me know if you want me to show you an example of how to do what I suggest in my previous comment. I'll gladly update my suggestion above. :-)

– Ittit
May 23 at 12:17








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361484%2fpassing-data-to-mat-menu%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript