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
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 { }
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 :)
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
.....................
.....................
import FormsModule
in addition to ReactiveFormsModule
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.
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
],