-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Add support for square, and curly brackets in ngClass #39835
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
Comments
This seem extremely confusing for no reason and not that easy to implement. Why don't you simply use a function which returns the correct list of classes? |
I agree with @Dlacreme here. The The broader feature request, here, is to support computed property names in Angular template expressions. Since, as @Dlacreme, points out the idea is to avoid too much logic in templates, I don't think that this is something that we are likely to implement in Angular core. |
On which part? So I could clarify it more.
I would love to work with this once we consider to support this proposed solution.
That's one of the solutions that we can do apart from the example workaround solution that I have provided which is great for complex and complicated operation.
Well, I agree to you as well on this one. But there are also not so complicated scenarios that can be easily done with
I believe it is because we handle multiple syntaxes, but once you get the idea of it, it isn't that confusing.
Yes, I agree with you on this that it is a bad practice to bloat a lot of logical operation on the |
I think, it's better way:
|
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
I prefer to keep all knowledge about styling in the HTML file itself. It plays nicely with tools like PurgeCSS. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
Don't we consider this feature request? I still think it would be really helpful. I'm thinking to create a POC for this one. |
@JoshuaAlzate It unfortunately didn't get the required amount of votes to be considered. Our feature request process requires at least 20 community upvotes before we add it to be considered. |
Support for the computed property name syntax is tracked in #43485. |
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. |
🚀 feature request
Relevant Package
This feature request is for @angular/common
Description
Currently, we do have a lot of syntaxes supported on ngClass. But there's no way to mix up the
[]
, and{}
syntax. There are scenarios that we will need a ternary operator to choose between two sets of classes dynamically, and there's also chances that we just need one.Describe the solution you'd like
I setup a sample where I describe the solution I like.
As you can see in there, I am comparing the key name of the object by putting it in square brackets. And when the condition false to any of the class stated, it will be return as a property key name.
This is what I have in mind, but it would be cleaner if we can handle it without explicitly putting
true
on it.Describe alternatives you've considered
Currently, the workaround for this is to put it on a square bracket array syntax and pass an empty class in case the condition falls to the other condition.
The text was updated successfully, but these errors were encountered: