Two-way binding in Angular 2 with NgModel and mutating bound property?

前端 未结 2 1922
深忆病人
深忆病人 2020-12-19 03:51

I am using Angular 2 beta 5.

Here\'s my view:


         


        
2条回答
  •  误落风尘
    2020-12-19 04:13

    For binding textarea values you can use the change-function:

    Template

    
    

    Component

    export class AppComponent implements OnInit {
      private textareaValue = '';
      doTextareaValueChange(ev) {
        try {
          this.textareaValue = ev.target.value;
        } catch(e) {
          console.info('could not set textarea-value');
        }
      }
    }
    

提交回复
热议问题