how to access model or view variable in angular 4 for two way data binding

there is no scope variable in Angular 2+.

In Angular 2+ there is NgModel which helps you with two way binding.

To access value of text area in your component.

In html

<textarea class="form-control" [(NgModel)]=comment placeholder="Add Comment">
<input type="button" value="Add" (click)="AddComment()" />

In component:




Here comment var will always be mapped to inputs in textarea.

Leave a Comment