|
|
@@ -7,9 +7,11 @@ import {
|
|
7
|
7
|
ReactiveFormsModule,
|
|
8
|
8
|
Validators,
|
|
9
|
9
|
} from '@angular/forms';
|
|
|
10
|
+import { ActivatedRoute } from '@angular/router';
|
|
10
|
11
|
import { AppHeader } from '../../share/header/app-header';
|
|
11
|
12
|
import { AppSideMenu } from '../../share/side-menu/app-side-menu';
|
|
12
|
13
|
import { DankaService } from '../../services/dankaService';
|
|
|
14
|
+import { Danka } from '../../models/danka';
|
|
13
|
15
|
|
|
14
|
16
|
@Component({
|
|
15
|
17
|
selector: 'app-danka-edit',
|
|
|
@@ -18,7 +20,7 @@ import { DankaService } from '../../services/dankaService';
|
|
18
|
20
|
styleUrl: './danka-edit.scss',
|
|
19
|
21
|
})
|
|
20
|
22
|
export class DankaEdit {
|
|
21
|
|
- private dankaService = inject(DankaService);
|
|
|
23
|
+ danka: Danka | undefined;
|
|
22
|
24
|
|
|
23
|
25
|
dankaForm = new FormGroup({
|
|
24
|
26
|
householdName: new FormControl('鈴木家'),
|
|
|
@@ -32,6 +34,32 @@ export class DankaEdit {
|
|
32
|
34
|
]),
|
|
33
|
35
|
});
|
|
34
|
36
|
|
|
|
37
|
+ constructor(
|
|
|
38
|
+ private dankaService: DankaService,
|
|
|
39
|
+ private route: ActivatedRoute,
|
|
|
40
|
+ ) {
|
|
|
41
|
+ const id = this.route.snapshot.params['id'];
|
|
|
42
|
+ if (id) {
|
|
|
43
|
+ this.danka = this.dankaService.getDankaById(id);
|
|
|
44
|
+
|
|
|
45
|
+ if (this.danka) {
|
|
|
46
|
+ this.dankaForm.patchValue({
|
|
|
47
|
+ householdName: this.danka.householdName,
|
|
|
48
|
+ householder: this.danka.householder,
|
|
|
49
|
+ postalCode: this.danka.postalCode,
|
|
|
50
|
+ address: this.danka.address,
|
|
|
51
|
+ });
|
|
|
52
|
+
|
|
|
53
|
+ this.phones.clear();
|
|
|
54
|
+
|
|
|
55
|
+ for (const phone of this.danka.phones) {
|
|
|
56
|
+ this.phones.push(this.createPhoneForm(phone.tel, phone.note));
|
|
|
57
|
+ }
|
|
|
58
|
+ }
|
|
|
59
|
+ }
|
|
|
60
|
+ console.log(this.danka);
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
35
|
63
|
get phones() {
|
|
36
|
64
|
return this.dankaForm.get('phones') as FormArray;
|
|
37
|
65
|
}
|
|
|
@@ -52,10 +80,14 @@ export class DankaEdit {
|
|
52
|
80
|
}
|
|
53
|
81
|
|
|
54
|
82
|
saveDanka() {
|
|
|
83
|
+ if (!this.danka) {
|
|
|
84
|
+ return;
|
|
|
85
|
+ }
|
|
|
86
|
+
|
|
55
|
87
|
const formValue = this.dankaForm.value;
|
|
56
|
88
|
|
|
57
|
89
|
const updatedDanka = {
|
|
58
|
|
- id: '1',
|
|
|
90
|
+ id: this.danka.id,
|
|
59
|
91
|
householdName: formValue.householdName ?? '',
|
|
60
|
92
|
householder: formValue.householder ?? '',
|
|
61
|
93
|
postalCode: formValue.postalCode ?? '',
|