英文:
Passthrough function in parameters not working
问题
当我单击 snackbar 中的按钮时,我看到 callButtonAction()
中的 console.log(1)
,但 this.close()
没有被触发。我在这里漏掉了什么?
英文:
I have an array of announcements, each announcement shows up in a snackbar and has some text and a button:
// announcements.services.ts
notificationConfig: {
buttons: [
{
text: this.translateService.instant(_('Go to Insights dashboard')),
action: () => {
this.router.navigate(['/dm/statistics/insights']);
this.dismissAnnouncement(AnnouncementName.INSIGHTS_DASHBOARD);
},
},
],
},
// toast-notification.html
<div *ngFor="let button of buttons" class="buttonWrapper">
<app-button (click)="callButtonAction(button.action)">{{ button.text | translate }}</app-button>
</div>
// toast-notification.component.ts
close() {
console.log(2);
this.onClose.emit();
}
callButtonAction(action: (closeHandler: CloseHandler) => void) {
console.log(1);
action(() => this.close());
}
When I click the button in the snackbar I do the see the console.log(1)
from the callButtonAction()
but the this.close()
is not being fired.
What I am missing here?
答案1
得分: 2
看起来你没有使用action
中提供的处理程序,这是你的代码示例:
notificationConfig: {
buttons: [
{
text: this.translateService.instant('转到洞察仪表板'),
action: (callback) => {
this.router.navigate(['/dm/statistics/insights']);
this.dismissAnnouncement(AnnouncementName.INSIGHTS_DASHBOARD);
callback()
},
},
],
},
英文:
Looks like you are not using the handler given to action
in action(() => this.close())
.
Try this:
notificationConfig: {
buttons: [
{
text: this.translateService.instant(_('Go to Insights dashboard')),
action: (callback) => {
this.router.navigate(['/dm/statistics/insights']);
this.dismissAnnouncement(AnnouncementName.INSIGHTS_DASHBOARD);
callback()
},
},
],
},
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论