If you are working with Angular (not the older version, AngularJS 1.x), it's important to adjust the NgModel syntax accordingly:
For HTML (template):
<input type="text"
[(ngModel)]="newUser"
style="text-align:center"/>
<button (click)="onAddUser()" >Add User</button>
In your TypeScript file:
export class YourComponent {
newUser: string;
onAddUser(){
alert(this.newUser); //retrieve the input value
}
}
Don't forget to import the FormsModule as well:
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
imports: [
CoreModule,
FormsModule
],
})
export class AppModule {}