下面预定义的 Primeeng 消息服务用于显示弹出通知
import { MessageService } from "primeng/components/common/messageservice
@Component({
selector: "student-wizard",
providers: [MessageService],
templateUrl: "student-wizard.component.html",
styleUrls: ["student-wizard.component.css"]
})
constructor(
private messageService: MessageService)
{}
从 HTML 我们调用下面的方法:
public hideDialog(): void {
this.messageService.add({
severity: "info",
summary: "Student Updation Terminated",
detail: "No updation performed"
});
this.router.navigateByUrl("studentTask", { relativeTo: this.route });
}
但是,在执行时没有错误,也没有显示弹出消息。
最佳答案
这是因为您正在导航到另一条路线,因此它不会显示任何消息。
为避免这种情况,将您的选择器移动到 app.component.html 中的应用级别
<p-growl [(value)]="globalService.msgs"></p-growl>
并尝试将来自某个全局服务的所有消息推送到它将使您的导航以及消息
关于Angular 2 Primeng 消息服务未显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50410239/