two way binding with safe navigation operator

前端 未结 2 397
迷失自我
迷失自我 2020-11-27 06:39

What is the best way to use two-way-binding (syntax-sugar) in Angular 2 with the safe navigation operator. I\'ve tried the following.



        
相关标签:
2条回答
  • 2020-11-27 07:18
    <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.x.y.z=val;
        }
    }
    

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

    0 讨论(0)
  • 2020-11-27 07:22

    You can split up- and downwards-binding like

    <input [ngModel]="x?.y?.z" (ngModelChange)="x?.y?.z ? x.y.z = $event : null"> 
    
    0 讨论(0)
提交回复
热议问题