无法导入ReactiveFormsModule

时间:2019-01-09 21:24:53

标签: angular

在app.module.ts中导入ReactiveFormsModule时,出现错误:

compiler.js:2427 Uncaught Error: Template parse errors:
No provider for ControlContainer ("<div class="container">
    <div class="row">
      [ERROR ->]<form class="col s12" id="reg-form">
        <div class="row">
          <div class="input-field col "): ng:///AppModule/LoginComponent.html@2:6
.
.
.

任何人都知道是什么原因造成的?该模块可能存在问题,因为当我删除所有HTML时,我仍然得到它,并且像在文档中一样将其导入。当我删除导入应用程序时,没有错误。

2 个答案:

答案 0 :(得分:0)

这是导入,当然没有箭头:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
-> import { ReactiveFormsModule } from '@angular/forms';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginComponent } from './components/login/login.component';
import { RegisterComponent } from './components/register/register.component';
import { HeaderComponent } from './components/header/header.component';
import { FooterComponent } from './components/footer/footer.component';
import { SidenavComponent } from './components/sidenav/sidenav.component';
import { MyworksheetsComponent } from './components/myworksheets/myworksheets.component';
import { AddworksheetComponent } from './components/addworksheet/addworksheet.component';
import { ProfileComponent } from './components/profile/profile.component';

import { ValidateService } from './services/validate/validate.service';
import { UserService } from './services/user/user.service';

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    RegisterComponent,
    HeaderComponent,
    FooterComponent,
    SidenavComponent,
    MyworksheetsComponent,
    AddworksheetComponent,
    ProfileComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    -> ReactiveFormsModule
  ],
  providers: [
    ValidateService,
    UserService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

我创建了一个新的test-app,它可以正常工作,因此在模块或导入方式方面都没有问题。

答案 1 :(得分:0)

您需要将指令添加到所有components.html中创建的任何表单中 示例:

<form [formGroup]=""> </form>

这样做可以消除错误。