Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngModel on number input

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">
like image 401
Zachscs Avatar asked Oct 27 '25 05:10

Zachscs


1 Answers

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">
like image 141
Sajeetharan Avatar answered Oct 29 '25 19:10

Sajeetharan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!