angular - 为什么我在 ng-template 中双击?
问题描述
我有以下模板:
<table class="table table-borderless tablelist-custom-style">
<tbody>
<ng-container [ngTemplateOutlet]="ordersTableHeadTemplate"></ng-container>
</tbody>
</table>
<ng-template #ordersTableHeadTemplate>
<tr>
<th class="align-bottom">
<div class="custom-control custom-checkbox" (click)="test()">
</th>
</tr>
</ng-template>
当我这样做时,(click)="test()"
我得到了两次点击而不是一次:
方法是:
test() {
console.log('1');
}
解决方案
NgTemplateOutlet是一个结构指令,用 asterix 调用。尝试相应地调用它:
<ng-container *ngTemplateOutlet="ordersTableHeadTemplate"></ng-container>
推荐阅读
- android - 使用 twitter kit sdk 在我的 android 应用程序中使用 twitter 登录时授权失败
- r - 变量“PKG_CXXFLAGS”中的不可移植标志
- tomcat - 如何使用两个 SSL 配置 Tomcat7
- c# - 无法加载 DLL Microsoft.Data.SqlClient.x86.dll(来自 HRESULT 的异常:0x800707E)
- python - python中“输入错误”的原因是什么?
- python - 如何为异常中的特定错误消息编写 if 语句?
- laravel - 使用 Github Actions,我如何构建准备好部署的资产?
- c-preprocessor - 为什么我的 C 预处理器使用空格忽略这些宏?
- matrix - scipy 稀疏矩阵求和导致密集矩阵 - 如何强制执行结果稀疏性?
- javascript - 使用 pdf2htmljs 创建多个 pdf