45 lines
1016 B
TypeScript
45 lines
1016 B
TypeScript
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
import {
|
|
Contact,
|
|
ContactService,
|
|
ContactFormService,
|
|
} from '@nested-forms/contact';
|
|
import { FormGroup, FormArray } from '@angular/forms';
|
|
import { Subscription } from 'rxjs';
|
|
|
|
@Component({
|
|
selector: 'base-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.css'],
|
|
})
|
|
export class AppComponent implements OnInit, OnDestroy {
|
|
contact: Contact;
|
|
form: FormGroup;
|
|
|
|
private subscription: Subscription;
|
|
|
|
constructor(
|
|
private service: ContactService,
|
|
private formService: ContactFormService,
|
|
) {}
|
|
|
|
public ngOnInit() {
|
|
this.subscription = this.service
|
|
.loadContact()
|
|
.subscribe((data: Contact) => {
|
|
this.contact = data;
|
|
this.form = this.formService.createForm(data);
|
|
});
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
if (this.subscription) {
|
|
this.subscription.unsubscribe();
|
|
}
|
|
}
|
|
|
|
get addresses(): FormArray {
|
|
return this.form.get('addresses') as FormArray;
|
|
}
|
|
}
|