如何以 angular 反应形式从 html 中删除特定的动态元素
How to remove a particular dynamic element from html in angular reactive form
我创建了一个动态反应表单,我可以使用它动态添加或删除字段,一切正常。当我点击下面的 + 号时,我得到的结果是 -
我想从最后一行删除单选按钮(和/或),就像它是 3 行一样,我只想要第 1 行和第 2 行,它不应该出现在第 3 行。我尝试了很多,但我无法实现。
有人可以帮忙吗?
只需在 *ngFor 中使用,let last=last
和一个 *ngIf="!last"
参见 the docs
<div formArrayName="example"
*ngFor="let a of exampleForm.get('example').value;
let i = index ;
let last=last; <!--add the let last=last-->
trackBy: trackByFn">
...
<div class= "operators" *ngIf="!last">
...
</div>
</div>
我创建了一个动态反应表单,我可以使用它动态添加或删除字段,一切正常。当我点击下面的 + 号时,我得到的结果是 -
我想从最后一行删除单选按钮(和/或),就像它是 3 行一样,我只想要第 1 行和第 2 行,它不应该出现在第 3 行。我尝试了很多,但我无法实现。
有人可以帮忙吗?
只需在 *ngFor 中使用,let last=last
和一个 *ngIf="!last"
参见 the docs
<div formArrayName="example"
*ngFor="let a of exampleForm.get('example').value;
let i = index ;
let last=last; <!--add the let last=last-->
trackBy: trackByFn">
...
<div class= "operators" *ngIf="!last">
...
</div>
</div>