Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

NG-Zorro中使用Message和Notification组件服务报错

版本
"@angular/core": "9.1.3",
"ng-zorro-antd": "9.1.2",

shared.module.ts

`import { NgZorroAntdModule} from 'ng-zorro-antd';`


@NgModule({
  imports: [NgZorroAntdModule],
  exports: [NgZorroAntdModule]
  ...
  

app.module.ts引入shared.module.ts

import { SharedModule } from a pp/shared/shared.module';

@NgModule({
  imports: [
SharedModule

style全局引入

@import "~ng-zorro-antd/ng-zorro-antd.min.css";

页面中使用message报错

xx.component.ts

`import { NzMessageService } from 'ng-zorro-antd/message';`

`public message: NzMessageService,`

`this.message.info('This is a normal message');`

错误

ERROR TypeError: Cannot read property 'appendChild' of undefined
    at NbOverlayContainerAdapter._createContainer (index.js?4782:2405)
    at NbOverlayContainerAdapter.OverlayContainer.getContainerElement (overlay.js?6d88:645)
    at Overlay._createHostElement (overlay.js?6d88:2619)
    at Overlay.create (overlay.js?6d88:2586)
    at NzNotificationService.NzMNService.withContainer (ng-zorro-antd-message.js?579d:123)
    at NzNotificationService.createInstance (ng-zorro-antd-notification.js?cb8b:759)
    at NzNotificationService.blank (ng-zorro-antd-notification.js?cb8b:703)
    at LoginComponent.test (login.component.ts?6dcb:119)
    at LoginComponent_Template_span_click_8_listener (login.component.html?3614:5)
    at executeListenerWithErrorHandling (core.js?4d84:15026)

求解?我该怎么办???


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...