【发布时间】:2019-03-29 19:34:36
【问题描述】:
我正在尝试实现 PrimeNG 烤面包机,但它没有出现,不确定我缺少什么。我按照这样的步骤操作:
npm install primeng --save
npm install primeicons --save
我在 angular-cli 样式中添加了以下内容:
"node_modules/primeicons/primeicons.css",
"node_modules/primeng/resources/themes/nova-light/theme.css",
"node_modules/primeng/resources/primeng.min.css"
在我导入的 app.module.ts 中
ToastModule,
BrowserAnimationsModule
在提供者中,我有来自 primeng/api 的 MessageService。
现在,在我的 http 请求服务中,我添加了这段代码:
get(url: string, showSuccessToast?: boolean, toastMessage?: string) {
const result = this.http.get(url)
.pipe(map((response: Response) => {
if (showSuccessToast) {
this.messageService.add({severity: 'success', summary: 'Success!', detail: toastMessage});
}
return response;
}),
catchError(response => this.handleError(response))
);
return result;
}
在我发出 get 请求的组件服务中,我为 showSuccess 添加了 true,为 message 添加了一个字符串。
在app.component.ts我加了:<p-toast></p-toast>
没有抛出错误,烤面包机只是没有弹出......
【问题讨论】:
-
尝试删除 showSuccessToast 条件并在返回响应时仅显示 toast
-
@Roj 当我在该行(this.messageService.add.....)上放置断点时,它执行了添加功能,但由于某种原因烤面包机没有出现,showSuccessToast 工作正常