-
Notifications
You must be signed in to change notification settings - Fork 27k
feat: support as syntax in template/* bindings …
#15025
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
Conversation
|
Can we avoid using |
|
@mprobst as pointed out here #15020 (comment) ES2015 uses it very much in the same way as to the proposed way here, also I do challenge you to find a more fitting word |
|
@Toxicable yeah, the ES6 imports are a point, but that's more of a renaming situation (and also more similar to casts), where this looks to me more like an assignment. We couldn't make |
|
@mprobst As explained here #15020 (comment) and in the comment following it explains that |
|
I wonder if we could use a different symbol to make the assignment more clear and remove the overlap? |
|
If the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so both let i=index and index as i are supported, right? do you think it's a good idea to have multiple ways to do the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we take away let then we break a whole lot of people. So, yes both will be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we discussed this after this comment was posted and decided that we do want to remove the old way. @mhevery did I understand the conclusion of the conversation correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should add a console warning that let syntax is deprecated (similar to template element) so it will be easier to remove it in v5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old way can't be removed as it would break a lot of people. Think *ngFor="let item of items" What was discussed was to remove *ngIf="exp; let var" However, it turns out that can't be removed either as it would make the else statement weird.
So in summary. Old syntax is supported but the new syntax is preferred. Both will continue to work.
3022f82 to
4787d03
Compare
IgorMinar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ 👍 🦄 🌈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we discussed this after this comment was posted and decided that we do want to remove the old way. @mhevery did I understand the conclusion of the conversation correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I LOVE that the as can be used for all the local variables. It makes the whole syntax look so much more consistent and cleaner. ❤️
|
With regards to the It's also worthwhile keeping in mind that nowhere in Angular templates we use types or have affordances for explicit type position in the syntax, so I that's another argument why the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right to me as it is much more lax in the syntax than you probably intent. You probably meant this to be !this.next.isOperator(chars.$SEMICOLON) && !this.next.isOperator(chars.$COMMA) && because optionalCharacter will advance the token which appears not what you intended.
If you make the above change you need to undelete line 717 an put it after your block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Closes angular#15020 Showing the new and the equivalent old syntax. - `*ngIf="exp as var1”` => `*ngIf="exp; let var1 = ngIf”` - `*ngFor="var item of itemsStream |async as items”` => `*ngFor="var item of itemsStream |async; let items = ngForOf”`
* feat(common): support `as` syntax in template/* bindings Closes angular#15020 Showing the new and the equivalent old syntax. - `*ngIf="exp as var1”` => `*ngIf="exp; let var1 = ngIf”` - `*ngFor="var item of itemsStream |async as items”` => `*ngFor="var item of itemsStream |async; let items = ngForOf”` * feat(common): convert ngIf to use `*ngIf="exp as local“` syntax * feat(common): convert ngForOf to use `*ngFor=“let i of exp as local“` syntax * feat(common): expose NgForOfContext and NgIfContext
|
Why is this limited to |
|
@realappie it is not limited, if you write your own structural directive it will work there |
* feat(common): support `as` syntax in template/* bindings Closes angular#15020 Showing the new and the equivalent old syntax. - `*ngIf="exp as var1”` => `*ngIf="exp; let var1 = ngIf”` - `*ngFor="var item of itemsStream |async as items”` => `*ngFor="var item of itemsStream |async; let items = ngForOf”` * feat(common): convert ngIf to use `*ngIf="exp as local“` syntax * feat(common): convert ngForOf to use `*ngFor=“let i of exp as local“` syntax * feat(common): expose NgForOfContext and NgIfContext
|
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. |
Closes #15020
Showing the new and the equivalent old syntax.
*ngIf="exp as var1”=>
*ngIf="exp; let var1 = ngIf”*ngFor="var item of itemsStream |async as items”=>
*ngFor="var item of itemsStream |async; let items = ngForOf”