36 lines
940 B
TypeScript
36 lines
940 B
TypeScript
import { ContactService } from './../../../../libs/contact/src/lib/contact.service';
|
|
import { Contact } from '@nested-forms/contact';
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
import { FormGroup, FormBuilder } from '@angular/forms';
|
|
import { Subscription } from 'rxjs';
|
|
|
|
@Component({
|
|
selector: 'nested-forms-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.css']
|
|
})
|
|
export class AppComponent implements OnInit, OnDestroy {
|
|
title = 'parent-form';
|
|
|
|
contact: Contact;
|
|
form: FormGroup;
|
|
|
|
private subscription: Subscription
|
|
|
|
constructor(private fb: FormBuilder, private service: ContactService) {
|
|
this.form = this.fb.group({});
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.subscription = this.service.loadContact().subscribe((data: Contact) => {
|
|
this.contact = data;
|
|
});
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
if (this.subscription) {
|
|
this.subscription.unsubscribe();
|
|
}
|
|
}
|
|
}
|