如何在动态控制中添加到Angular 4中的表单后调用自定义方法?

时间:2017-11-29 12:54:42

标签: angular

我在Angular 4中使用SharePoint。我想在为表单创建动态控件之后调用一个方法。能否为您提供相同的解决方案?在按下" +"我的表格中的图标。

<div *ngFor="let item of actionPlans; let i = index">
<div class="row"><div class="form-group"><label>Action Plan</label>
<input type="text" class="form-control" name="actionPlan-{{i}}" [(ngModel)]="item.actionPlan">
</div></div></div>

打字稿代码如下: -

private actionPlans: any = [];private addActionPlan() { this.actionPlans.push({}); }

我想在将动态项添加到屏幕后调用以下方法。在下面的方法中,我想访问控件ID和一些操作。你能不能请任何人帮助我吗?

private getActionPlan() { // do some actvities }

此致 菲利普

1 个答案:

答案 0 :(得分:0)

我猜你的“控制”实际上是一个行动计划?

如果您需要在按 + 按钮后调用自定义方法,则需要使用简单的

将eventHandler添加到按钮中
(click)="doSomething()"

但是你可能已经这样做了,所以如果你想调用你的方法母鸡,你已经添加了控件,你必须这样做

doSomething() {
  // Your code to add a control
  this.myCustomMethod();
}

这很简单。