如何在结构指令中将函数传递给createEmbeddedView?

问题描述 投票:-2回答:1

我尝试在指令主体中执行此操作:

let fn = () => {
  alert("ok");
};

export class DirDirective {
this.vcr.createEmbeddedView(this.tpl, {
        $implicit: num,
        fn: fn
      });
}

模板是:

<ng-container *dir="true; let num; let fn=fn">
    <option (click)="fn"></option>
</ng-container>

当我点击时:

 (click)="fn"

它不调用函数let fn = () => {}

我的想法是动态更改处理程序的单击次数

angular angular7 angular8
1个回答
1
投票

您的问题在这里:

(click)="fn"

应该是

(click)="fn()"

StackBlitz Example

© www.soinside.com 2019 - 2024. All rights reserved.