I'd like to bind the input of a number input to a variable in my typescript file. I thought ngModel would be appropriate and made an input: <input [{ngModel}]="tRating" type="number" min="1" max="10"> tRating being of type number in the .ts file. Unfortunately I'm getting an error :
Can't bind to '{ngModel}' since it isn't a known property of 'input'. ("
<input [ERROR ->][{ngModel}]="pRating" type="number" min="1" max="10">
You need to import FormsModule into your app.module.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule
],
and syntax should be [(ngModel)] not [{ngModel}]
<input [(ngModel)]="tRating" type="number" min="1" max="10">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With