33 lines
876 B
TypeScript
33 lines
876 B
TypeScript
import {
|
|
ChangeDetectionStrategy,
|
|
Component,
|
|
Input,
|
|
OnInit,
|
|
} from '@angular/core';
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
import { Name } from '@nested-forms/contact';
|
|
|
|
@Component({
|
|
selector: 'nested-forms-name',
|
|
templateUrl: './name.component.html',
|
|
styleUrls: ['./name.component.css'],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class NameComponent implements OnInit {
|
|
@Input() nameGroup: FormGroup;
|
|
|
|
static buildForm(name: Name): FormGroup {
|
|
return new FormGroup({
|
|
firstName: new FormControl(name ? name.firstName : ''),
|
|
lastName: new FormControl(name ? name.lastName : ''),
|
|
middleName: new FormControl(name ? name.middleName : ''),
|
|
prefix: new FormControl(name ? name.prefix : ''),
|
|
suffix: new FormControl(name ? name.suffix : ''),
|
|
});
|
|
}
|
|
|
|
constructor() {}
|
|
|
|
ngOnInit() {}
|
|
}
|