angular - 获取 TypeError:使用 ngx-notification-bar 时无法读取未定义的属性(读取“取消订阅”)
问题描述
我已经使用这个ngx-notification-bar 文档中提到的步骤实现了通知栏
在app.component.ts
文件中,有以下部分代码
this.notificationBarService.create({ message: '<b>Free Shipping </b>', type: NotificationType.Info, allowClose: true, autoHide: false, hideOnHover: false, isHtml: true });
在app.component.html
文件中,有以下部分代码
<notification-bar
[ngStyle]="{ height: '3px', background: 'white' }"
></notification-bar>
我可以在我的页面上看到通知栏。但是当我从页面转到任何其他页面(或组件)时app.component.html
,我在控制台中收到以下错误,并且组件没有加载,而是有一个空白屏幕
core.js:6228 ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'unsubscribe')
TypeError: Cannot read properties of undefined (reading 'unsubscribe')
at NotificationBarComponent.ngOnDestroy (ngx-notification-bar.js:165)
at executeOnDestroys (core.js:14405)
at cleanUpView (core.js:14304)
at destroyViewTree (core.js:14073)
at destroyLView (core.js:14255)
at RootViewRef.destroy (core.js:15120)
at ComponentRef$1.destroy (core.js:34191)
at RouterOutlet.deactivate (router.js:9122)
at ActivateRoutes.deactivateRouteAndOutlet (router.js:4023)
at ActivateRoutes.deactivateRouteAndItsChildren (router.js:3981)
at resolvePromise (zone-evergreen.js:798)
at resolvePromise (zone-evergreen.js:750)
at zone-evergreen.js:860
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:41632)
at ZoneDelegate.invokeTask (zone-evergreen.js:398)
at Zone.runTask (zone-evergreen.js:167)
at drainMicroTaskQueue (zone-evergreen.js:569)
at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:484)
at invokeTask (zone-evergreen.js:1621)
据我了解,这与不调用有关ngOnDestroy()
。谁能帮我解决这个问题?
解决方案
推荐阅读
- xml - 如何使用 PowerShell 读取 XML 文件并过滤所需数据
- javascript - JS onclick 事件未触发
- gatsby - 如何在 gatsby 源插件上加载本地图像?
- python - AttributeError:“NoneType”对象在 Keras 中没有属性“_inbound_nodes”
- node.js - 无法从 nginx 反向代理后面的 node.js docker 容器访问静态 css 和 js 文件
- reactjs - 使用 firebase 在 React js 中工作:TypeError: Cannot read property 'uid' of null
- java - 如何用Java逐块解析大型XML文件
- javascript - 节点逐行从文件中读取数据...处理它并将其保存回问题
- java - 设置所有活动操作栏文本
- css - 桌面和手机的 css 文件之间的反应生产混乱