2019-09-05 03:47:09 +00:00
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
import { FormGroup } from '@angular/forms';
|
2019-09-06 02:56:08 +00:00
|
|
|
import {
|
|
|
|
Contact,
|
|
|
|
ContactService,
|
|
|
|
ContactFormService,
|
|
|
|
} from '@nested-forms/contact';
|
2019-09-05 02:38:01 +00:00
|
|
|
import { Subscription } from 'rxjs';
|
2019-09-02 19:23:01 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'nested-forms-root',
|
|
|
|
templateUrl: './app.component.html',
|
2019-09-05 03:47:09 +00:00
|
|
|
styleUrls: ['./app.component.css'],
|
2019-09-02 19:23:01 +00:00
|
|
|
})
|
2019-09-05 02:38:01 +00:00
|
|
|
export class AppComponent implements OnInit, OnDestroy {
|
|
|
|
contact: Contact;
|
2019-09-03 03:27:28 +00:00
|
|
|
form: FormGroup;
|
|
|
|
|
2019-09-05 02:38:01 +00:00
|
|
|
private subscription: Subscription;
|
|
|
|
|
2019-09-05 03:47:09 +00:00
|
|
|
constructor(
|
|
|
|
private service: ContactService,
|
|
|
|
private formService: ContactFormService,
|
|
|
|
) {}
|
2019-09-05 02:38:01 +00:00
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.subscription = this.service
|
|
|
|
.loadContact()
|
|
|
|
.subscribe((data: Contact) => {
|
|
|
|
this.contact = data;
|
2019-09-05 03:47:09 +00:00
|
|
|
this.form = this.formService.createForm(data);
|
2019-09-05 02:38:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if (this.subscription) {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2019-09-02 19:23:01 +00:00
|
|
|
}
|