最近学习了下angular,利用Angular CLI 在本地搭建了个环境,然后装了个ant.design的NG-ZORRO库,试了下用ui的脚手架来创建组件
代码语言:javascript复制ng g ng-zorro-antd:form-normal-login login
创建完成发现访问项目的时候,在使用nz-form时报错Can't bind to 'formGroup' since it isn't a known property of 'form',百度了下解决方案:
需要从@angular/forms导入ReactiveFormsModule。因为FormGroupDirective 指令属于ReactiveFormsModule一部分。
导入后的app.module.ts
代码语言:javascript复制import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NewsComponent } from './news/news.component';
import { NgZorroAntdModule, NZ_I18N, zh_CN } from 'ng-zorro-antd';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { registerLocaleData } from '@angular/common';
import zh from '@angular/common/locales/zh';
import { LoginComponent } from './login/login.component';
registerLocaleData(zh);
@NgModule({
declarations: [
AppComponent,
NewsComponent,
LoginComponent
],
imports: [
BrowserModule,
AppRoutingModule,
NgZorroAntdModule,
FormsModule,
HttpClientModule,
BrowserAnimationsModule,
ReactiveFormsModule
],
providers: [{ provide: NZ_I18N, useValue: zh_CN }],
bootstrap: [AppComponent]
})
export class AppModule { }