-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(MatMenuTrigger): null should be a valid value, in order to have conditional submenus #24030
Comments
Bumping the priority, because this has come up multiple times. |
crisbeto
added a commit
to crisbeto/material2
that referenced
this issue
Feb 17, 2022
…trigger Adds support for conditionally removing the menu from a menu trigger by passing in `null`. Fixes angular#24030.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
forsti0506
pushed a commit
to forsti0506/components
that referenced
this issue
Apr 3, 2022
…trigger (angular#24437) Adds support for conditionally removing the menu from a menu trigger by passing in `null`. Fixes angular#24030.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Feature Description
Very often we find the need to have a menu, where their submenus are conditional. That is, they may or may not exist, base on a condition.
Ideally, the following should work:
Current Workaround
However, since matMenuTriggerFor cannot be null, the above code does not compile. The current solution is duplicating code with
*ngIf
:Why This is Needed
At first sight, it doesn't look that terrible, but as we start to add other attributes (classes, i18n suff, and other directives), and as the button content also becomes richer (with icons and internationalized text). The code duplication is hard to maintain and can easily introduce bugs in our app.
For example, for the following code:
with the current workaround, the code grows to:
with this proposal, the code would only need to be modified slightly:
Note: Creating a bogus empty submenu does not work as a workaround.
Use Case
Very often I find the need to have a menu, where their submenus are conditional. That is, they may or may not exist, base on a condition.
The text was updated successfully, but these errors were encountered: