From 21eb505c3b3ca33fde096ed29e6271ecd93a7fd5 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Wed, 23 Aug 2023 15:04:11 +0800 Subject: [PATCH] Inheriting classes can set data themselves as long as they call `initForm()` #9819 Sometimes data is not coming from routing, but from somewhere else, such as MatDialog data. Those use-cases should also be supported with `isUpdatePage()`. So as long as they call themselves `initForm()` after changing data, it's fine. --- projects/natural/src/lib/classes/abstract-detail.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/natural/src/lib/classes/abstract-detail.ts b/projects/natural/src/lib/classes/abstract-detail.ts index 14027341..e742a51f 100644 --- a/projects/natural/src/lib/classes/abstract-detail.ts +++ b/projects/natural/src/lib/classes/abstract-detail.ts @@ -77,7 +77,7 @@ export class NaturalAbstractDetail< * so the form does not switch from creation mode to update mode without an actual reload of * model from DB (by navigating to update page). */ - #updatePage = false; + #isUpdatePage = false; public constructor(protected readonly key: string, public readonly service: TService) { super(); @@ -88,7 +88,6 @@ export class NaturalAbstractDetail< this.route.data.subscribe(data => { this.data = merge({model: this.service.getDefaultForServer()}, data[this.key]); this.data = merge(this.data, omit(data, [this.key])); - this.#updatePage = !!this.data.model.id; this.initForm(); }); } else { @@ -107,7 +106,7 @@ export class NaturalAbstractDetail< * This should be used instead of checking `data.model.id` directly, in order to type guard and get proper typing */ protected isUpdatePage(): this is {data: {model: ExtractTone}} { - return this.#updatePage; + return this.#isUpdatePage; } public update(now = false): void { @@ -229,6 +228,7 @@ export class NaturalAbstractDetail< } protected initForm(): void { + this.#isUpdatePage = !!this.data.model.id; this.form = this.service.getFormGroup(this.data.model); }