admin管理员组文章数量:1316003
i have an Angular V19.0 application , there is an issue with primeNg toast and confirm services. i have provided the services in a core module which is imported in app.module.ts
but when ever i inject and use these services , i get 2 dialogs or toasts per click. also the first click does not show the toast or confirm dialog.
and also the toast component does not work if the key
property is not provided.
-----------------------HTML----------
<ng-container *ngIf="toastMessageKey | async as tKey">
<p-toast position="top-left" baseZIndex="999999" [key]="tKey" life="100000"/>
</ng-container>
------------------------TS-----------
this.toastMessageKey = this.messageService.messageObserver.pipe(
filter((x) => x !== null && x !== undefined),
map((t) => (<ToastMessageOptions>t).key ?? 'toast'),
);
without the code above , the toast message does not even show it self. and i even tried replicating my code to another project with the same structure (lazy loaded modules...etc)
it worked like a charm.
i don't know where have i done a mistake. I'm busting my head to a wall for this. it does not give me any errors or anything at all. but all i figured out was the confirm or toast observer are being triggered twice by each call.
------Layout service---
openToast(toast: ToastMessageOptions) {
this.toastService.add(toast);
}
i have an Angular V19.0 application , there is an issue with primeNg toast and confirm services. i have provided the services in a core module which is imported in app.module.ts
but when ever i inject and use these services , i get 2 dialogs or toasts per click. also the first click does not show the toast or confirm dialog.
and also the toast component does not work if the key
property is not provided.
-----------------------HTML----------
<ng-container *ngIf="toastMessageKey | async as tKey">
<p-toast position="top-left" baseZIndex="999999" [key]="tKey" life="100000"/>
</ng-container>
------------------------TS-----------
this.toastMessageKey = this.messageService.messageObserver.pipe(
filter((x) => x !== null && x !== undefined),
map((t) => (<ToastMessageOptions>t).key ?? 'toast'),
);
without the code above , the toast message does not even show it self. and i even tried replicating my code to another project with the same structure (lazy loaded modules...etc)
it worked like a charm.
i don't know where have i done a mistake. I'm busting my head to a wall for this. it does not give me any errors or anything at all. but all i figured out was the confirm or toast observer are being triggered twice by each call.
------Layout service---
openToast(toast: ToastMessageOptions) {
this.toastService.add(toast);
}
Share
Improve this question
asked Jan 29 at 21:44
Pouya BabaiePouya Babaie
7910 bronze badges
2
- did you add <p-toast /> tag in parent of this component? i mean maybe you added this tag twice – Mojtaba Nejad Poor Esmaeili Commented Jan 30 at 0:38
- @MojtabaNejadPoorEsmaeili unfortunatly , there is only one p-taost tag in app component. – Pouya Babaie Commented Jan 31 at 14:58
1 Answer
Reset to default 1The problem could be due to SSR being on, it open once on the server and once on the browser, the solution is to wrap the logic in a defer block so that executes only on the browser.
@defer() {
<ng-container *ngIf="toastMessageKey | async as tKey">
<p-toast position="top-left" baseZIndex="999999" [key]="tKey" life="100000"/>
</ng-container>
}
本文标签: Angular PrimeNg singleton services ( ConfirmMessage) show twice in viewStack Overflow
版权声明:本文标题:Angular PrimeNg singleton services ( Confirm , Message) show twice in view - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741995448a2409949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论