简体   繁体   English

如何使用FormArray将第一个对象值推入数组

[英]how to push first object values in to array using FormArray

I tried to push first object only into array but it's adding all the objects. 我试图将第一个对象仅推入数组,但它添加了所有对象。 I have attached the screen shot. 我已经附上了屏幕截图。 I have three fields first is firstname and last name street. 我有三个字段,第一个是名字,第二个是姓氏。 I need to show only first object value. 我只需要显示第一个对象值。 but it's showing all the data. 但它显示所有数据。 How to display first one object, it having multiple objectives also? 如何显示第一个对象,它也有多个目标? Below is the CODE URL 以下是CODE URL

https://stackblitz.com/edit/angular-formgroup2-first?file=app%2Fapp.component.ts https://stackblitz.com/edit/angular-formgroup2-first?file=app%2Fapp.component.ts

Get rid of the mapper, and only push first element 摆脱映射器,只推第一个元素

   let formArr = <FormArray>this.myForm.controls.users;
      formArr.push(fb.group({
        firstname: this.users[0].firstname,
        lastname: this.users[0].lastname,
        street: this.users[0].street
      }))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM