nested-forms/apps/static-factory-methods/src/app/address-list/address-list.component.ts

32 lines
814 B
TypeScript
Raw Normal View History

import { Component, Input, OnInit } from '@angular/core';
import { FormArray, FormBuilder } from '@angular/forms';
import { Address } from '@nested-forms/contact';
import { AddressComponent } from '../address/address.component';
@Component({
selector: 'nested-forms-address-list',
templateUrl: './address-list.component.html',
styleUrls: ['./address-list.component.css']
})
export class AddressListComponent implements OnInit {
@Input() addressArray: FormArray;
static createContactAddressListForm(addresses: Address[], fb: FormBuilder): FormArray {
const list: FormArray = fb.array([]);
if (addresses) {
addresses.forEach(addr => {
list.push(AddressComponent.createContactAddressForm(addr, fb));
});
}
return list;
}
constructor() { }
ngOnInit() {
}
}