36 lines
832 B
TypeScript
36 lines
832 B
TypeScript
import {
|
|
ChangeDetectionStrategy,
|
|
Component,
|
|
Input,
|
|
OnInit,
|
|
} from '@angular/core';
|
|
import { FormArray } 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'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class AddressListComponent implements OnInit {
|
|
@Input() addressArray: FormArray;
|
|
|
|
static buildForm(addresses: Address[]): FormArray {
|
|
const list: FormArray = new FormArray([]);
|
|
|
|
if (addresses) {
|
|
addresses.forEach(addr => {
|
|
list.push(AddressComponent.buildForm(addr));
|
|
});
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
constructor() {}
|
|
|
|
ngOnInit() {}
|
|
}
|