【问题标题】:Set PrimeNG confirm message from template从模板设置 PrimeNG 确认消息
【发布时间】:2017-10-05 12:10:23
【问题描述】:

我正在使用 PrimeNg Collection 中的 ConfirmDialog 组件。我可以这样设置我的消息:

this.confirmationService.confirm({
      message: 'my message',
    });

它可以工作,但问题是如果我需要一大组带有其他组件的标签,它就会变得混乱。我想将我的消息写在一个 HTML 模板中,旁边是 p-confirmDialog 标记,其中嵌入了 Angular 的指令和组件。

我如何做到这一点?

【问题讨论】:

  • stackoverflow.com/a/45789799/8468804 也许在这篇文章中实现类似我的回答作为解决方法。请注意,但如果您想为变量/属性实现模板,无论哪种方式都会很混乱。
  • 我不想要黑客和变通方法。如果 Angular 如此出色,那么一切都应该以正确的方式完成。

标签: angular primeng


【解决方案1】:

这是另一种方法,我认为这是一种更合适的方法。

HTML

<p-confirmDialog appendTo="body">
<ng-template pTemplate="body">
    <span class="ui-confirmdialog-message">{{message}}</span>"
</ng-template>

TS

    ...
constructor(private confirmationService: ConfirmationService) {}

private message = `Do you want to change your status to <span style="color:red">inactive</span>` //your template html;
...
this.confirmationService.confirm({
  header: "Some header",
  message: this.message,
  accept: () => {
    //Do something
  }
});

您始终可以有专门的服务来调用ConfirmationService 并根据需要传递message

【讨论】:

    猜你喜欢
    • 2017-10-19
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 2017-12-22
    相关资源
    最近更新 更多