-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Feature Request💥 Add Destructuring Support in @for Loops and async if's #57374
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
That would be a nice addition. 👍 in that case, we probably need to add this for so:
can be:
|
This would be very nice! Additionally, I would love array destructuring assignments as well (not sure if that should be a separate feature request):
This would really streamline workflows with our own custom iterables. |
If we add destructing it should be supported in all Angular expressions instead of being constrained to some usage sites |
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. |
Uh oh!
There was an error while loading. Please reload this page.
Relevant Package
This feature request is for @angular/core.
No response
Description
With Angular's recent introduction of the new control flow syntax, which is much more aligned with TypeScript, I believe it’s the perfect time to bring in a feature that many developers would find incredibly useful—destructuring in templates.
Destructuring is something I often use in TypeScript to simplify code and make it more readable. It allows us to unpack values from arrays or properties from objects into distinct variables, which can really tidy up the code. Right now, Angular templates don’t natively support this within @for() loops or async if's, which feels like a missed opportunity.
Imagine being able to write something like this:
This would allow developers to directly destructure objects or arrays right in the template, making the templates cleaner and more intuitive.
Proposed solution
Add support for destructuring within @for() loops and async if's in Angular templates. The syntax could be very similar to how destructuring works in TypeScript, allowing for a seamless experience between the two.
For example:
This approach would make the template code more concise and closer to the TypeScript code, improving both readability and maintainability.
Alternatives considered
Custom Pipes or Directives: Another alternative is to create custom pipes or directives that handle destructuring. But this can lead to over-engineering and makes the codebase harder to understand, especially for teams that may not be familiar with these custom solutions.
The text was updated successfully, but these errors were encountered: