未捕获(承诺):错误:模板解析错误:由于它不是“ form”的已知属性,因此无法绑定到“ formGroup”

时间:2019-07-28 14:12:47

标签: angular forms typescript validation ionic4

我想将表单验证实施到我的Ionic表单中。但它总是给我一个错误,即formGroup不是form的属性。

chrome error

我已经将模块导入了app.modules.ts

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

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    IonicStorageModule.forRoot(),
    ReactiveFormsModule,
    FormsModule,
    HttpModule

  ],

和我的landing-page.ts

import { Validators, FormBuilder, FormGroup, FormControl, ReactiveFormsModule } from '@angular/forms';

在这里创建验证器

export class LandingPage implements OnInit {
  public formUserSetup: FormGroup;
  constructor(
    private menu: MenuController,
    public formBuilder: FormBuilder
  ) {
    this.menu.enable(false);

    this.formUserSetup = formBuilder.group({
      firstname : new FormControl('', Validators.compose([Validators.required])),
      lastname : new FormControl('', Validators.compose([Validators.required])),
      email: new FormControl('', Validators.compose([Validators.required]))
    });
   }

  ngOnInit() {

  }

}

表单本身:

<form  [formGroup]="formUserSetup">
   <ion-input type='text' formControlName="firstname"></ion-input>
</form>

0 个答案:

没有答案