Skip to content

2-way binding syntax, e.g., [(ngModel)], should support elvis operator #7697

Description

@wardbell
  • 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions