I'm using angular7. Just make some textbox and then alert that textbox value. But I can't get the values in typescript. Please help me guys how to proceed more this step.
about.component.html
<input type="text" name="username">
<button (click)="lgbtnclick()" type="button" name="button"></button>
about.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.scss']
})
export class AboutComponent implements OnInit {
name : string;
constructor() { }
ngOnInit() {
}
lgbtnclick(){
alert(this.name)
console.log(Error)
}
}
alert message:
undefined
ngmodelto bind textbox value to name varible .name is undefined it's not initialized<input type="text" name="username" [(ngModel)]="name">