还需要显示以前的字段部分的删除按钮

发布于 2025-01-27 11:22:53 字数 1164 浏览 5 评论 0原文

在此处,如果我单击“添加”按钮删除按钮显示了最后一个字段。需要显示所有各个字段部分的删除按钮。

这是JSON结构

    {
  "headline": [
    {
      "headlineText": "example en headline",
      "language": "en"
    },
    {
      "headlineText": "example de headline",
      "language": "de"
    }
  ],
  "bodyText": [
    {
      "bodyText": "example en bodytext",
      "language": "en"
    },
    {
      "bodyText": "example de bodytext",
      "language": "de"
    }
  ],
  "location": {
    "name": "mkontheway",
    "openingHours": [
      {
        "day": "Mon-frd",
        "timing": "10.00PM-9AM"
      }
    ],
  }
}

“当前代码的屏幕截图”

修改了屏幕截图以获取实际要求。需要添加的每个字段的右侧删除按钮

请帮助我如何以角度实现这一目标。

Stackblitz Link

Here if I click on add button delete button is showing for the last fields. Need to show delete button for all the respective fields sections.

this is the json structure

    {
  "headline": [
    {
      "headlineText": "example en headline",
      "language": "en"
    },
    {
      "headlineText": "example de headline",
      "language": "de"
    }
  ],
  "bodyText": [
    {
      "bodyText": "example en bodytext",
      "language": "en"
    },
    {
      "bodyText": "example de bodytext",
      "language": "de"
    }
  ],
  "location": {
    "name": "mkontheway",
    "openingHours": [
      {
        "day": "Mon-frd",
        "timing": "10.00PM-9AM"
      }
    ],
  }
}

Screenshot for current code

Modified the screenshot for actual requirement. Need delete button on the right side for each fields which gets added
Need delete for each fields which gets added

Please help me how to achieve this in angular.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

影子是时光的心 2025-02-03 11:22:54

看台:

It looks like you're using ngModel on the same form field as formControlName.
Support for using the ngModel input property and ngModelChange event with
reactive form directives has been deprecated in Angular v6 and will be removed
in a future version of Angular.

For more information on this, see our API docs here:
https://angular.io/api/forms/FormControlName#use-with-ngmodel

这是一个警告,然后每次单击添加按钮时都会出现错误:

ERROR
Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '{
"headline": [
{
"headlineText": "example headline",
"language": "en"
},
{
"headlineText": null,
"language": null
}
],
"bodyText": [
{
"bodyText": "example bodytext",
"language": "en"
}
],
"location": {
"name": "mkontheway",
"openingHours": [
{
"day": "Mon-frd",
"timing": "10.00PM-9AM"
}
],
"address": {
"postCode": null,
"country": null
}
}
}'. Current value: '{
"headline": [
{
"headlineText": "example headline",
"language": "en"
},
{
"headlineText": null,
"language": "en"
}
],
"bodyText": [
{
"bodyText": "example bodytext",
"language": "en"
}
],
"location": {
"name": "mkontheway",
"openingHours": [
{
"day": "Mon-frd",
"timing": "10.00PM-9AM"
}
],
"address": {
"postCode": null,
"country": null
}
}
}'.. Find more at https://angular.io/errors/NG0100

Look the console:

It looks like you're using ngModel on the same form field as formControlName.
Support for using the ngModel input property and ngModelChange event with
reactive form directives has been deprecated in Angular v6 and will be removed
in a future version of Angular.

For more information on this, see our API docs here:
https://angular.io/api/forms/FormControlName#use-with-ngmodel

This is a warning, and then you have an error everytime you click the add button:

ERROR
Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '{
"headline": [
{
"headlineText": "example headline",
"language": "en"
},
{
"headlineText": null,
"language": null
}
],
"bodyText": [
{
"bodyText": "example bodytext",
"language": "en"
}
],
"location": {
"name": "mkontheway",
"openingHours": [
{
"day": "Mon-frd",
"timing": "10.00PM-9AM"
}
],
"address": {
"postCode": null,
"country": null
}
}
}'. Current value: '{
"headline": [
{
"headlineText": "example headline",
"language": "en"
},
{
"headlineText": null,
"language": "en"
}
],
"bodyText": [
{
"bodyText": "example bodytext",
"language": "en"
}
],
"location": {
"name": "mkontheway",
"openingHours": [
{
"day": "Mon-frd",
"timing": "10.00PM-9AM"
}
],
"address": {
"postCode": null,
"country": null
}
}
}'.. Find more at https://angular.io/errors/NG0100
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文