javascript - Canσ#39;t bind to 39;ngModelέ#39 since it isτ#39;t a known property of 39;input constant#39

Mots clés : javascriptangulartypescriptinputjavascript

meilleur 4 Réponses javascript - Canσ#39;t bind to 39;ngModelέ#39 since it isτ#39;t a known property of 39;input constant#39

vote vote

91

import { FormsModule } from '@angular/forms';  [...]  @NgModule({   imports: [     [...]     FormsModule   ],   [...] }) 
vote vote

81

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms';  // <<<< import it here import { AppComponent } from './app.component';  @NgModule({   declarations: [     AppComponent   ],   imports: [     BrowserModule, FormsModule // <<<< And here   ],   providers: [],   bootstrap: [AppComponent] })  export class AppModule { } 
/**  * `ngModel` forces an additional change detection run when its inputs change:  * E.g.:  * ```  * <div>{{myModel.valid}}</div>  * <input [(ngModel)]="myValue" #myModel="ngModel">  * ```  * I.e. `ngModel` can export itself on the element and then be used in the template.  * Normally, this would result in expressions before the `input` that use the exported directive  * to have and old value as they have been  * dirty checked before. As this is a very common case for `ngModel`, we added this second change  * detection run.  *  * Notes:  * - this is just one extra run no matter how many `ngModel` have been changed.  * - this is a general problem when using `exportAs` for directives!  */ 
[ngModelOptions]="{standalone: true}" 
vote vote

78

import { FormsModule } from '@angular/forms'; 
@NgModule({     imports: [        FormsModule     ], }) 
vote vote

63

import { NgModule }      from '@angular/core'; import { FormsModule } from '@angular/forms';  import { authRouting } from './auth.routing'; import { LoginComponent, SignupComponent } from './auth.component';  @NgModule({   imports:      [     authRouting,     FormsModule    ],   declarations: [     SignupComponent,     LoginComponent   ] }) export class AuthModule { } 

Questions similaires