Angular 2 Primeng 消息服务不显示消息

Vai*_*ant 5 service message primeng angular

下面预定义的 Primeng 消息服务用于显示弹出通知

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)
{}
Run Code Online (Sandbox Code Playgroud)

我们从 HTML 中调用以下方法:

 public hideDialog(): void {
        this.messageService.add({
            severity: "info", 
            summary: "Student Updation Terminated",
            detail: "No updation performed"
        });
        this.router.navigateByUrl("studentTask", { relativeTo: this.route });
    }
Run Code Online (Sandbox Code Playgroud)

但是,执行时没有错误,也没有显示弹出消息。

Par*_*ain 3

这是因为您正在导航到其他路线,因此它不会显示任何消息。

为了避免这种情况,请将选择器移动到应用程序级别,如 app.component.html 中

<p-growl [(value)]="globalService.msgs"></p-growl>
Run Code Online (Sandbox Code Playgroud)

并尝试将来自某些全球服务的所有消息推送到它将使您的导航以及消息启用