Angular-表单数组推送特定索引 [英] Angular - Form Array push specific index

查看:96
本文介绍了Angular-表单数组推送特定索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

addStop() {
    const control = <FormArray>this.editForm.controls['stops'];
    control.push(this.initStop());
}

我有这段代码在表单数组的底部添加一个停止".但是我想将新的停靠点"添加到最后一个停靠点之前,而不是最后一个停靠点.

I have this code to add a "stop" at the bottom of the form array. But I want to add the new "stop" not to the last position, but one position before the last stop.

例如,这是行不通的(根本不,我知道数字是错误的.Splice函数根本不存在)

This doesn't work for example (not at all, I know that the numbers are wrong. Splice function doesn't exist at )

control.splice(2, 0, this.initStop());

推荐答案

使用 FormArray #insert :

control.insert(<position>, this.initStop());

这篇关于Angular-表单数组推送特定索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆