Angular 2 error: cannot resolve all parameters for FormGroup

I follow the Thoughtram tutorial for FormBuilder http://blog.thoughtram.io/angular/2016/06/22/model-driven-forms-in-angular-2.html I copied the code and changed several variable names. I am using Angular 2.1.2, Typescript 2.0.8 and Angular Material2 (from Google). Atom Typescript does not report an error on any page. However, I get errors while loading, and the page does not load using this new code.

zone.js:388 Unhandled Promise rejection: Can't resolve all parameters for FormGroup: (?, ?, ?). ; Zone: <root> ; Task: Promise.then ; Value: Error: Can't resolve all parameters for FormGroup: (?, ?, ?).(…) Error: Can't resolve all parameters for FormGroup: (?, ?, ?).
at CompileMetadataResolver.getDependenciesMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14598:21)
at CompileMetadataResolver.getTypeMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14499:28)
at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14642:43)
at Array.forEach (native)
at CompileMetadataResolver.getProvidersMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14622:21)
at CompileMetadataResolver.getDirectiveMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14262:36)
at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14367:51)
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14361:51)
at RuntimeCompiler._compileComponents (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17063:49)consoleError @ zone.js:388_loop_1 @ zone.js:417drainMicroTaskQueue @ zone.js:421ZoneTask.invoke @ zone.js:339
2016-11-10 16:01:40.394 zone.js:390 Error: Uncaught (in promise): Error: Can't resolve all parameters for FormGroup: (?, ?, ?).(…)consoleError @ zone.js:390_loop_1 @ zone.js:417drainMicroTaskQueue @ zone.js:421ZoneTask.invoke @ zone.js:339

HTML Example for an Apartment 4Rent.component.html

<form [formGroup]="registerApartment4RentForm" (submit)="onSubmit($event)">
  <md-input id="country" name="country" class="required" aria-labelledby="country" formControlName="country"
i18n-placeholder="select country placeholder" placeholder="Country" type="text"  size="30" maxlength="30">
  </md-input>

plus 4 more identical for state, city, street and zip code

AppComponent with the designer from the tutorial - in the application folder

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';

@Component({
    moduleId: module.id,
    selector: 'residence-app',
    templateUrl: "components/navigation/headerFooter.html",
    styleUrls: [ "components/navigation/styleHeaderFooter.css" ],
    providers: [
      FormBuilder,
      FormGroup
    ]
})
export class AppComponent implements OnInit {
    registerApartment4RentForm: FormGroup;
    constructor(private formBuilder: FormBuilder) {}
    ngOnInit() {
      this.registerApartment4RentForm = this.formBuilder.group({
        country: '',
        stateProvince: '',
        address: this.formBuilder.group({
          streetAddress: '',
          zipCode: '',
          city: ''
        })
      });
    }
}

In headerFooter.html in templateUrl there is some html for the header and footer and

            <div>
                <router-outlet></router-outlet>
            </div>

, 4Rent.component.html , . - ///4Rent.component(s)

, ?

+4
1

Angular ? , , .

( , )

Edit

:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@anglar/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';

@NgModule({
  imports: [BrowserModule, ReactiveFormsModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}

ReactiveFormsModule

+4

Source: https://habr.com/ru/post/1660450/


All Articles