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

查看:23
本文介绍了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.

例如这不起作用(一点也不,我知道数字是错误的.拼接功能在 处不存在)

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#插入:

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

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

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