Angular动画会在删除FormArray项时触发表单提交
创始人
2024-10-24 13:31:37
0
  1. 避免将动画应用于表单组件或与表单组件相关的元素。

  2. 手动禁用表单提交事件。

在组件的HTML模板中,在表单标签上添加(ngSubmit)="onSubmit($event)"属性,并在组件的Typescript文件中定义onSubmit()方法。在onSubmit()方法中添加以下代码:

event.preventDefault();

这将阻止表单提交并解决问题。

示例代码:

HTML模板

Typescript文件

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, FormArray } from '@angular/forms';

@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css']
})
export class FormComponent implements OnInit {
  form: FormGroup;

  constructor() { }

  ngOnInit() {
    this.form = new FormGroup({
      items: new FormArray([
        new FormGroup({
          name: new FormControl()
        }),
        new FormGroup({
          name: new FormControl()
        })
      ])
    });
  }

  get items(): FormArray {
    return this.form.get('items') as FormArray;
  }

  deleteItem(index: number) {
    this.items.removeAt(index);
  }

  onSubmit(event: Event) {
    event.preventDefault();
    // handle form submission
  }
}

相关内容

热门资讯

透视练习!wejoker免费脚... 透视练习!wejoker免费脚本(HHpoker脚本)确实是真的有辅助神器(哔哩哔哩)进入游戏-大厅...
今天上午!微乐小程序黑科技,微... 今天上午!微乐小程序黑科技,微乐小程序破解版修改器(透视)好像是有辅助脚本(哔哩哔哩)在进入软件靠谱...
随着!微信微乐游戏辅助脚本,微... 随着!微信微乐游戏辅助脚本,微乐辅助脚本(透视)真是存在有辅助工具(哔哩哔哩)1、公共底牌简单,透视...
透视办法!aapoker怎么控... 透视办法!aapoker怎么控制牌(WePoKer价格)果然是真的有辅助软件(哔哩哔哩)1、玩家可以...
透视手筋!wepoker能不能... 透视手筋!wepoker能不能透视(德普之星辅助软件)好像真的有辅助神器(哔哩哔哩)1、操作简单,无...
辅助透视!微信微乐游戏辅助脚本... 辅助透视!微信微乐游戏辅助脚本,陕西微乐小程序修改器(透视)一贯是真的辅助挂(哔哩哔哩)1)免费钻石...
透视攻略!wpk是真的还是假的... 透视攻略!wpk是真的还是假的(AApoker底牌)果然真的是有辅助软件(哔哩哔哩)1、每一步都需要...
明白辅助挂!微乐小程序黑科技,... 明白辅助挂!微乐小程序黑科技,微乐自建房辅助工具2025在哪(透视)总是是有辅助软件(哔哩哔哩)1、...
透视手册!wepokerplu... 透视手册!wepokerplus开挂(AApoker透视脚本)竟然是真的有辅助脚本(哔哩哔哩)1)w...
透视好友!微乐小程序黑科技免费... 透视好友!微乐小程序黑科技免费,小程序微乐游戏辅助器(透视)竟然有辅助神器(哔哩哔哩)1、完成有辅助...