拜托,我被困在这里的人们;我在一天之后遇到了这个错误,在开发Angular2
应用程序(稳定版)时让我发疯了:
Error: Template parse errors:
Can't bind to 'FormGroup' since it isn't a known property of 'form'.
("<form name="pageForm"
[ERROR ->][FormGroup]="pageForm"
class="lc-edit-page" novalidate>
<div class="row">
<div class="col-lg-6"")
奇怪的是,当搜索时,有一个显而易见的解决方案正在进行
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Module file
中的。我做到了:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { UsersListComponent } from './modals';
import { LcFormComponent } from './lc-form';
import { AddUComponent } from '../../../../+u/shared/components';
import { UIRouterModule } from 'ui-router-ng2';
import { TranslateModule } from 'ng2-translate';
@NgModule({
declarations: [
LcFormComponent,
UsersListComponent
],
imports: [
FormsModule,
BrowserModule,
UIRouterModule,
TranslateModule,
LcFormComponent,
UsersListComponent,
ReactiveFormsModule
],
providers: [],
exports: [
FormsModule,
BrowserModule,
UIRouterModule,
TranslateModule,
LcFormComponent,
UsersListComponent,
ReactiveFormsModule
],
entryComponents:
[
AddUComponent,
UsersListComponent
]
})
export class ParModule {}
绑定错误在LcFormComponent
的HTML中,在其他组件中它可以顺利运行但在这里我真的不知道问题出在哪里。
以下是LcFormComponent.ts
导入部分:
import { Input, Component, AfterContentInit } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators, NgForm } from '@angular/forms';
import * as lodash from 'lodash';
import { TranslateService } from 'ng2-translate';
import { NotificationsService } from 'angular2-notifications';
import { NgbModal, NgbModalRef, NgbModalOptions } from '@ng-bootstrap/ng-bootstrap';
import { UsersListComponent } from '../modals';
import { AddUComponent } from '../../../../../+users/shared/components/modals';
@Component({
selector: 'app-lc-form',
templateUrl: './lc-form.component.html',
styleUrls: ['./lc-form.component.scss']
})
export class LcPageComponent {
// ....
}
请帮忙吗?
答案 0 :(得分:1)
您在html中使用的是[FormGroup]
,而应该是[formGroup]
。