Kaynağa Gözat

[add]

檀家編集画面からデータ更新できる
poohr 1 ay önce
ebeveyn
işleme
49c65b2df9

+ 3
- 3
src/app/pages/danka-detail/danka-detail.html Dosyayı Görüntüle

@@ -21,15 +21,15 @@
21 21
           </nav>
22 22
         </div>
23 23
 
24
-        <button type="button" class="edit-button">
24
+        <button type="button" class="edit-button" [routerLink]="['/danka-edit', danka?.id]">
25 25
           編集
26 26
         </button>
27 27
       </div>
28 28
 
29 29
       <section class="family-summary">
30 30
         <div class="family-name-area">
31
-          <p class="family-name">{{ danka?.householder }}</p>
32
-          <p class="family-head">世帯主: {{ danka?.householdName }}</p>
31
+          <p class="family-name">{{ danka?.householdName }}</p>
32
+          <p class="family-head">世帯主: {{ danka?.householder }}</p>
33 33
         </div>
34 34
 
35 35
         <div class="family-address">

+ 2
- 2
src/app/pages/danka-detail/danka-detail.ts Dosyayı Görüntüle

@@ -1,5 +1,5 @@
1 1
 import { Component } from '@angular/core';
2
-import { ActivatedRoute } from '@angular/router';
2
+import { ActivatedRoute, RouterLink } from '@angular/router';
3 3
 import { DankaService } from '../../services/dankaService';
4 4
 import { Danka } from '../../models/danka';
5 5
 import { AppHeader } from '../../share/header/app-header';
@@ -7,7 +7,7 @@ import { AppSideMenu } from '../../share/side-menu/app-side-menu';
7 7
 
8 8
 @Component({
9 9
   selector: 'app-danka-detail',
10
-  imports: [AppHeader, AppSideMenu],
10
+  imports: [AppHeader, AppSideMenu, RouterLink],
11 11
   templateUrl: './danka-detail.html',
12 12
   styleUrl: './danka-detail.scss',
13 13
 })

+ 34
- 2
src/app/pages/danka-edit/danka-edit.ts Dosyayı Görüntüle

@@ -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 ?? '',

Loading…
İptal
Kaydet