Compare commits
No commits in common. "00577f888e68a9f0e3ddfa604b1deb7eedd974a3" and "e26b48010d7ecc3c065b4fca1666b9e9930a52f2" have entirely different histories.
00577f888e
...
e26b48010d
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
|||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Kevin C. Coram
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -1,6 +1,10 @@
|
|||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Contact, ContactService } from '@nested-forms/contact';
|
||||
import { FormGroup, FormArray, FormBuilder } from '@angular/forms';
|
||||
import {
|
||||
Contact,
|
||||
ContactService,
|
||||
ContactFormService,
|
||||
} from '@nested-forms/contact';
|
||||
import { FormGroup, FormArray } from '@angular/forms';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
|
@ -14,14 +18,17 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||
|
||||
private subscription: Subscription;
|
||||
|
||||
constructor(private service: ContactService, private fb: FormBuilder) {}
|
||||
constructor(
|
||||
private service: ContactService,
|
||||
private formService: ContactFormService,
|
||||
) {}
|
||||
|
||||
public ngOnInit() {
|
||||
this.subscription = this.service
|
||||
.loadContact()
|
||||
.subscribe((data: Contact) => {
|
||||
this.contact = data;
|
||||
this.form = this.createForm(data);
|
||||
this.form = this.formService.createForm(data);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -31,39 +38,6 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
public createForm(model: Contact): FormGroup {
|
||||
const name = model.name;
|
||||
|
||||
const addresses: FormArray = this.fb.array([]);
|
||||
|
||||
const group = this.fb.group({
|
||||
name: this.fb.group({
|
||||
firstName: [name ? name.firstName : ''],
|
||||
lastName: [name ? name.lastName : ''],
|
||||
middleName: [name ? name.middleName : ''],
|
||||
prefix: [name ? name.prefix : ''],
|
||||
suffix: [name ? name.suffix : ''],
|
||||
}),
|
||||
addresses: addresses,
|
||||
});
|
||||
|
||||
if (model.addresses) {
|
||||
model.addresses.forEach(addr => {
|
||||
addresses.push(
|
||||
this.fb.group({
|
||||
line1: [addr ? addr.line_1 : ''],
|
||||
line2: [addr ? addr.line_2 : ''],
|
||||
city: [addr ? addr.city : ''],
|
||||
state: [addr ? addr.state : ''],
|
||||
postalCode: [addr ? addr.postalCode : ''],
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
get addresses(): FormArray {
|
||||
return this.form.get('addresses') as FormArray;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue