nested-forms/apps/global-form/src/app/app.component.ts

41 lines
925 B
TypeScript
Raw Normal View History

import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
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',
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;
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;
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
}