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)
求解?我该怎么办???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种全局的提示使用频繁,直接在根module中provides提供出去就好