import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { Contact, ContactService, ContactFormService, } from '@nested-forms/contact'; import { Subscription } from 'rxjs'; @Component({ selector: 'nested-forms-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(); } } }