onclick 中的字符串插值 (Ionic 2 + Angular 2)

String interpolation inside onclick (Ionic 2 + Angular 2)

简单的问题,我试图在我的 Ionic 2 应用程序中的 "onclick" 中传递一个字符串,但它一直给我一个错误。

<button onclick="window.plugins.socialsharing.shareViaWhatsApp(null, null, '{{sound.file}}', null)">Enviar no whats</button>

错误日志

 Can't bind to 'onclick' since it isn't a known native property

应该是这样的:

<button (click)="share(sound.file)">Enviar no whats</button>

在你的组件中

public share(file: string): void {
    window.plugins.socialsharing.shareViaWhatsApp(null, null, file, null);
}

您应该避免在视图中包含 逻辑,而是将其放在组件代码中。