- I'm submitting a ...
[ ] bug report
[x] feature request
[ ] support request
- Do you want to request a feature or report a bug?
Feature
- What is the current behavior?
A2 supports the elvis operator (?.) in property bindings but not "two-way" bindings.
This is ok: [ngModel]="hero?.name".
A2 throws an error if I write [(ngModel)]="hero?.name" because this de-sugars (in part) to (ngModelChange)="hero?.name=$event" and the elvis operator (?.) is not supported in assignments.
Today's workaround is [ngModel]="hero && hero.name". We can do better.
Recommend that template statements support elvis in assignments.
For example, the following <input> element event binding — (input)="hero?.name = $event.target.value" — should assign the value to hero.name if hero != null; if hero == null it should do nothing.
It follows that we will then support [(ngModel)]="hero?.name" which was the original motivation for this request.
- What is the motivation / use case for changing the behavior?
Elvis is useful in binding syntax ... both in property binding template expressions and event binding template statements involving assignment.
The 2-way binding syntax today prevents usage of elvis, even if we only wanted it for the property binding half of that syntax.
- Please tell us about your environment:
- Angular version: 2.0.0-beta.11 everywhere
[ ] bug report
[x] feature request
[ ] support request
Feature
A2 supports the elvis operator (?.) in property bindings but not "two-way" bindings.
This is ok:
[ngModel]="hero?.name".A2 throws an error if I write
[(ngModel)]="hero?.name"because this de-sugars (in part) to(ngModelChange)="hero?.name=$event"and the elvis operator (?.) is not supported in assignments.Today's workaround is
[ngModel]="hero && hero.name". We can do better.https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).
Recommend that template statements support elvis in assignments.
For example, the following
<input>element event binding —(input)="hero?.name = $event.target.value"— should assign the value tohero.nameifhero != null; ifhero == nullit should do nothing.It follows that we will then support
[(ngModel)]="hero?.name"which was the original motivation for this request.Elvis is useful in binding syntax ... both in property binding template expressions and event binding template statements involving assignment.
The 2-way binding syntax today prevents usage of elvis, even if we only wanted it for the property binding half of that syntax.