瀏覽代碼

[add]

serviceの家族情報を保存する処理を追加
poohr 3 週之前
父節點
當前提交
11a10b1549
共有 1 個檔案被更改,包括 7 行新增2 行删除
  1. 7
    2
      src/app/services/family-service.ts

+ 7
- 2
src/app/services/family-service.ts 查看文件

@@ -41,8 +41,13 @@ export class FamilyService {
41 41
     return this.families.find((family) => family.id === id);
42 42
   }
43 43
 
44
-  addFamily(family: Family) {
45
-    this.families.push(family);
44
+  saveFamily(updateFamily: Family) {
45
+    const index = this.families.findIndex((families) => families.id === updateFamily.id);
46
+    if (index === -1) {
47
+     this.families.push(updateFamily);
48
+     return;
49
+    }
50
+    this.families[index] = updateFamily;
46 51
   }
47 52
   // updateFamily(family: Family);
48 53
   // deleteFamily(id: string);

Loading…
取消
儲存