No provider for ControlContainer - Angular 5

后端 未结 8 1167
萌比男神i
萌比男神i 2020-12-09 14:26

I am converting a purchased, third-party template into an Angular 5 app, and just ran into an error. I am very new to Angular 5 (I know AngularJS well however) and don\'t un

相关标签:
8条回答
  • 2020-12-09 15:10

    Import FormsModule and ReactiveFormsModule in views.module.ts(custome module file) file works for me :

    views.module.ts

    import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { RouterModule } from '@angular/router';
    import { FormsModule, ReactiveFormsModule } from '@angular/forms';
    
    
    @NgModule({
      imports: [
        CommonModule,
        RouterModule,
        FormsModule,
        ReactiveFormsModule,
        ...
      ],
      declarations: [
        ...
      ],
      exports: [
       ...
      ],
      schemas: [NO_ERRORS_SCHEMA]
    })
    export class ViewsModule { }
    
    0 讨论(0)
  • 2020-12-09 15:16

    After spending 2 hours on it, i realised that when we import FormModule in app.module as well as in child.module then this kind of error occur. Simpley remove FormModule from child.module then error will be resolved :)

    0 讨论(0)
  • 2020-12-09 15:19

    I had this issue in Angular(Jasmin) Test cases.

    I have accidentally added angular form modules in the import of my Unit Test at beforeEach, one is FormModule (by angular) and other one is Custom FormModule.

    I need only Custom FormModule, once I removed the FormModule (by angular) the issue resolved

    beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [CustomTranslateModule.forRoot(),
        CustomRightPanelModule,
        CustomListModule,
        CustomInputTextModule,
        CustomMasterPageModule,
        CustomFormModule,
        FormModule, // this is unnecessary 
        .....................
        .....................
    
    0 讨论(0)
  • 2020-12-09 15:21

    import FormsModule in addition to ReactiveFormsModule

    0 讨论(0)
  • 2020-12-09 15:22

    If you are trying to display plain HTML form from an Angular component, use ngNoForm in <form> tag like this.

    <form ngNoForm>
    ...
    </form>
    

    This should prevent Angular from throwing Control Container Error.

    0 讨论(0)
  • 2020-12-09 15:28

    Edit the file "app.module.ts"; change the following instruction:

    import { ReactiveFormsModule } from '@angular/forms';
    

    with the following:

    import { ReactiveFormsModule, FormsModule } from '@angular/forms';
    

    Change the following piece of code:

      imports: [
        BrowserModule,
        ReactiveFormsModule
      ],
    

    with the following:

      imports: [
        BrowserModule,
        ReactiveFormsModule,
        FormsModule
      ],
    
    0 讨论(0)
提交回复
热议问题