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)

求解?我该怎么办???

阅读 3.4k
1 个回答

image.png
这种全局的提示使用频繁,直接在根module中provides提供出去就好

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题