我正在尝试这样做:
<button (click)="confirm('some message') ? someFunction() : anotherFunction()">Text</button>
这当然会失败,因为Angular会在其自己的代码中寻找Confirm()函数。编译失败,并显示如下错误语句:
ERROR in src\client\pages\x.component.html(72,114): : Property 'confirm' does not exist on type 'OurCustomComponent'.
有没有办法使这项工作?我确实意识到(现在才阅读文档),不允许使用某些javascript语法,但是尚不清楚是否有方法可以实现此目的。
您需要在组件中使用包装函数。
confirm(): void {
confirm('some message') ? this.someFunction() : this.anotherFunction();
}
<button (click)="confirm()">Text</button>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句