I am trying to bind ngModel from text input but it's is not working.
Here is my code:
Template:
<form (ngSubmit)="onSubmit()">
<div class="form-group">
<input type="text" class="form-control" [(ngModel)]="message">
</div>
<input type="submit">
</form>
Component:
export class Component implements OnInit {
message:string
onSubmit() {
console.log(this.message);
}
}
Always getting undefined value. How to bind value from the text input to variable?