我有组件LoginComponent在UsersModule
@NgModule({
declarations: [
UsersComponent,
LoginComponent
],
imports: [
ReactiveFormsModule
],
providers: [
]
})
export class UsersModule { }
为什么我不能绑定到'formGroup' ?我导入了必要的模块(ReactiveFormsModule)
也许是因为我在这里使用LoginComponent ?(AppRoutingModule)
const routes: Routes = [
{
path: '',
component: MainComponent,
},
{
path: 'users',
component: UsersComponent,
},
{
path: 'login',
component: LoginComponent,
},
{
path: '**',
redirectTo: '',
},
]
@NgModule({
imports: [
RouterModule.forRoot(routes),
FormsModule,
ReactiveFormsModule],
exports: [RouterModule],
})
export class AppRoutingModule {}
请帮助。在模板
<div class="login-container">
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<label for="username"> Name
<input type="text" id="username" formControlName="username">
</label>
<label for="password"> Pass
<input type="password" id="password" formControlName="password">
</label>
<button class="btn blue">Enter</button>
</form>
</div>
你导入UsersModule到AppModule了吗?
@NgModule({
declarations: [AppComponent],
imports: [
... some modules
UsersModule,
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
如果你不把模块导入AppModule,你就不能构建app