angular - PrimeNg p-growl 组件未正确显示,延迟后不会消失
问题描述
我正在尝试将 p-growl 组件用于通知,但不知何故,实际通知缺少关闭 X 按钮,并且在经过一定时间后不会消失。给你一个视觉印象:这是一个错误咆哮:
如您所见, tekst 显示的单词之间有很大的间隙,并且缺少 X 按钮。这是咆哮组件的代码。
组件.html
<p-growl [value]="msgs"></p-growl>
组件.ts
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { NotificationService } from '../Services/notification.service';
import { Message } from 'primeng/api';
@Component({
selector: 'app-notification',
templateUrl: './notification.component.html',
styleUrls: ['./notification.component.css']
})
export class NotificationComponent implements OnInit, OnDestroy {
msgs: Message[] = [];
subscription: Subscription;
constructor(private notificationService: NotificationService) { }
ngOnInit() {
this.subscribeToNotifications();
}
subscribeToNotifications() {
this.subscription = this.notificationService.notificationChange
.subscribe(notification => {
this.msgs.length = 0;
this.msgs.push(notification);
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
它适用于服务,我怀疑问题出在服务中,但这是服务的代码。
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
type Severities = 'success' | 'info' | 'warn' | 'error';
@Injectable({
providedIn: 'root'
})
export class NotificationService {
notificationChange: Subject<Object> = new Subject<Object>();
notify(severity: Severities, summary: string, detail: string) {
this.notificationChange.next({ severity, summary, detail });
}
}
谁能看到发生了什么?我认为这与错误的导入有关,但似乎并非如此,而且我正在为图标导入必要的 css 文件,所以不能这样。
谢谢
解决方案
好的解决了它,我忘了将这些行添加到我在 angular-cli.json 中的样式中并安装 primeicons。
"styles": [
"src/styles.css",
"node_modules/primeng/resources/themes/omega/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"node_modules/primeicons/primeicons.css",
此外,如果您希望咆哮声在一段时间后消失,您必须先将一个新的空数组分配给咆哮消息数组变量,然后再按如下方式:
this.msgs = [];
如果您不这样做,您将无法在推送第一条消息后推送任何新消息。有关更多信息,请参阅本文。https://www.primefaces.org/primeng-4-0-0-rc4-released/
推荐阅读
- python - django 库中缺少 raise ImproperlyConfigured
- java - 使用正则表达式模式验证域和子域的正则表达式是什么?
- tsql - 执行 SP_Open 游标导致 SMSS 出现严重错误
- javascript - 返回后该方法又是谁调用了它自己?
- excel - 从工作表中的不同单元格中提取数据
- python - 使用 python 包“bumps”将数据与耦合 ODE 拟合
- java - 将 rawQuery 的结果转换为对象
- dictionary - 如何将 POST 正文绑定到地图?
- amazon-web-services - 完成对所有实例的部署后的 AWS CodeDeploy 挂钩?
- error-handling - HERE Api - 已达到每日请求限制 - 但计划描述中并未提及