Two-way binding with elvis-operator

What is the best way to use two-way binding (syntax sugar) in Angular 2 using the elvis operator. I tried

<input [(ngModel)]="x?.y?.z"> 

But this is not supported.

Is there any way to use sth. like this?

+6
source share
2 answers

You can split the binding up and down as

 <input [ngModel]="x?.y?.z" (ngModelChange)="x?.y?.z ? xyz = $event : null"> 
+6
source
 <input [ngModel]="x?.y?.z" (keyup)="changeMe($event.target.value)"> {{x?.y?.z}} export class ParentCmp { x={y:{z:"a"}} changeMe(val) { console.log(val); this.xyz=val; } } 

http://plnkr.co/edit/ZBeSPqf4HUwLOeWSNfZJ?p=preview

+1
source

All Articles