Get value from Input text field in angular 5
You have wrong bound.
You need banana-in-box binding [(ngModel)]="serial"
instead of [ngModel]="serial"
()
in the binding will update serial
model everytime when the input will be changes. From input
into model
Single []
will just bind the data of serial
if it will be changed by code manually. This will cause to one-way binding - from model
into input
.
As you guess - together [()]
they will make two-way binding.
this is one way binding. from view to controller.
file code.component.html
<label >Code</label>
<input (input)="tcode=$event.target.value" type="text" class="form-control">
<button class="btn btn-success" (click)="submit()">Submit</button>
file code.component.ts
tcode : string;
submit() {
console.log("the code :" + this.tcode);
}