I'm currently working with Angular 7 and trying to create a textbox to display its value in an alert. However, I'm facing difficulty in fetching the textbox value in typescript. I would appreciate any guidance on how to proceed with this issue.
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)
}
}
The alert message shows:
undefined