官方文檔是這樣子的,抄下來會報錯,因為沒有后兩個設置
import { NgZorroAntdModule, NzConfig, NZ_CONFIG } from 'ng-zorro-antd';
const ngZorroConfig: NzConfig = {
// 注意組件名稱沒有 nz 前綴
message: { nzTop: 120 },
notification: { nzTop: 240 }
};
@NgModule({
declarations: [AppComponent],
imports: [
CommonModule
NgZorroAntdModule,
],
providers: [
{ provide: NZ_CONFIG, useValue: ngZorroConfig }
],
bootstrap: [AppComponent]
})
export class AppModule {}
實際操作步驟如下
進入\src\app\app.module.ts
import { NgZorroAntdModule, NzMessageConfig, NZ_MESSAGE_CONFIG } from 'ng-zorro-antd';
const NzMessageConfig: NzMessageConfig = {
nzTop: 200,
nzDuration: 5000
}
@NgModule({
declarations: [AppComponent],
imports: [
NgZorroAntdModule
],
providers: [ { provide: NZ_MESSAGE_CONFIG, useValue: NzMessageConfig }],
bootstrap: [AppComponent],
})
export class AppModule { }
保存刷新 OK
