diff --git a/src/app/components/base-param-input/base-param-input.component.ts b/src/app/components/base-param-input/base-param-input.component.ts index 7f9812f48be1b91fbf4f512b84f00815d02f0bc9..9d836d6d67451f6e2f8bf6c4193334aa57c57c71 100644 --- a/src/app/components/base-param-input/base-param-input.component.ts +++ b/src/app/components/base-param-input/base-param-input.component.ts @@ -44,8 +44,8 @@ export class NgBaseParam extends Observable { templateUrl: "../generic-input/generic-input.component.html", }) export class BaseParamInputComponent extends GenericInputComponent { - constructor(private intlService: InternationalisationService) { - super(); + constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) { + super(cdRef); } /** diff --git a/src/app/components/base/base.component.ts b/src/app/components/base/base.component.ts index 3d7cef25df2ae91b3ea70da0b5718ce23077e120..d1c3efca70e802d4b6e0ebeaacd8088168ebccac 100644 --- a/src/app/components/base/base.component.ts +++ b/src/app/components/base/base.component.ts @@ -1,6 +1,6 @@ -import { Output, EventEmitter, AfterViewChecked } from "@angular/core"; +import { Output, EventEmitter, AfterViewChecked, OnChanges } from "@angular/core"; -export abstract class BaseComponent implements AfterViewChecked { +export abstract class BaseComponent implements AfterViewChecked, OnChanges { /** * true après le 1er affichage du composant */ @@ -32,8 +32,12 @@ export abstract class BaseComponent implements AfterViewChecked { } } + public ngOnChanges() { + } + /** * appelé une fois, après l'affichage complet du composant */ - protected abstract afterFirstViewChecked(); + protected afterFirstViewChecked() { + } } \ No newline at end of file diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index e3359da1222fbaf06fc625b55869ad2eeb63f72d..578ab729d9656b35f21266348c97b9c49bc61eaa 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -1,4 +1,4 @@ -import { Input, Output, EventEmitter } from "@angular/core"; +import { Input, Output, EventEmitter, ChangeDetectorRef } from "@angular/core"; import { BaseComponent } from "../base/base.component"; @@ -79,6 +79,10 @@ export abstract class GenericInputComponent extends BaseComponent { */ private _errorMessageModel: string; + constructor(private cdRef: ChangeDetectorRef) { + super(); + } + private get isDisabled(): boolean { return this._inputDisabled; } @@ -90,6 +94,14 @@ export abstract class GenericInputComponent extends BaseComponent { this.onChange.emit({ "action": "valid", "value": this.isValid }); } + /** + * détection des changements dans l'UI par le ChangeDetector du framework + */ + protected detectChanges() { + if (this.cdRef != undefined) + this.cdRef.detectChanges(); + } + /** * calcul de la validité globale du composant (UI+modèle) */ @@ -107,6 +119,7 @@ export abstract class GenericInputComponent extends BaseComponent { private validateUI() { let { isValid, message } = this.validateUIValue(this._uiValue); this._errorMessageUI = message; + this.detectChanges(); this.setUIValid(isValid); return isValid; } @@ -121,6 +134,7 @@ export abstract class GenericInputComponent extends BaseComponent { private validateModel() { let { isValid, message } = this.validateModelValue(this.getModelValue()); this._errorMessageModel = message; + this.detectChanges(); this.setModelValid(isValid); } @@ -162,6 +176,7 @@ export abstract class GenericInputComponent extends BaseComponent { this._model = v; this.afterSetModel(); this.updateAll(); + this.detectChanges(); } /** @@ -192,10 +207,9 @@ export abstract class GenericInputComponent extends BaseComponent { } /** - * appelé après le 1er affichage du composant - * @see BaseComponent + * appelé quand les @Input changent */ - protected afterFirstViewChecked() { + public ngOnChanges() { this.updateAll(); } diff --git a/src/app/components/ngparam-input/ngparam-input.component.ts b/src/app/components/ngparam-input/ngparam-input.component.ts index a5ce7ec9bc5a0c13f070117c016bd05e4fce484e..23cd83d34a3f247a019b70d1829d8ca084c4eefd 100644 --- a/src/app/components/ngparam-input/ngparam-input.component.ts +++ b/src/app/components/ngparam-input/ngparam-input.component.ts @@ -28,13 +28,13 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse */ private _tmp: number; - constructor(private intlService: InternationalisationService) { - super(); + constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) { + super(cdRef); } /** - * appelé avant le changement de modèle - */ + * appelé avant le changement de modèle + */ protected beforeSetModel() { if (this._paramDef != undefined) this._paramDef.removeObserver(this); diff --git a/src/app/components/param-field-line/param-field-line.component.ts b/src/app/components/param-field-line/param-field-line.component.ts index 604f87eb0a2c206c2d149749f9591215acaf4089..b6c40c242fc449b6452bf9b15d4b849e4b6bdf0e 100644 --- a/src/app/components/param-field-line/param-field-line.component.ts +++ b/src/app/components/param-field-line/param-field-line.component.ts @@ -1,4 +1,4 @@ -import { Component, ViewChild, Input, Output, EventEmitter, AfterViewChecked } from "@angular/core"; +import { Component, ViewChild, Input, Output, EventEmitter, OnChanges } from "@angular/core"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; import { NgParameter, ParamRadioConfig } from "../../formulaire/ngparam"; @@ -25,7 +25,7 @@ import { FormulaireService } from "../../services/formulaire/formulaire.service" }` ] }) -export class ParamFieldLineComponent implements AfterViewChecked { +export class ParamFieldLineComponent implements OnChanges { @Input("param") private _param: NgParameter; @@ -257,7 +257,7 @@ export class ParamFieldLineComponent implements AfterViewChecked { this.emitValidity() } - public ngAfterViewChecked() { + public ngOnChanges() { this._ngParamInputComponent.model = this._param; this._ngParamInputComponent.showError = this.isRadioFixChecked; } diff --git a/src/app/components/param-values/ngparam-max.component.ts b/src/app/components/param-values/ngparam-max.component.ts index f6cbbbeaad606a29534d9e0e4464d1d4c4ef302d..ae6852ef8e79280815c026b34f15fca5ccf84e6f 100644 --- a/src/app/components/param-values/ngparam-max.component.ts +++ b/src/app/components/param-values/ngparam-max.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from "@angular/core"; +import { Component, Input, ChangeDetectorRef } from "@angular/core"; import { NumericalString } from "jalhyd"; @@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam"; templateUrl: "../generic-input/generic-input.component.html" }) export class NgParamMaxComponent extends GenericInputComponent { - constructor(private intlService: InternationalisationService) { - super(); + constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) { + super(cdRef); } /** diff --git a/src/app/components/param-values/ngparam-min.component.ts b/src/app/components/param-values/ngparam-min.component.ts index cd00396c1899ee7f42deeb0eb795b6b9953804e8..162307df29dc144bc54d98b6fb3857c49b03812d 100644 --- a/src/app/components/param-values/ngparam-min.component.ts +++ b/src/app/components/param-values/ngparam-min.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from "@angular/core"; +import { Component, Input, ChangeDetectorRef } from "@angular/core"; import { NumericalString } from "jalhyd"; @@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam"; templateUrl: "../generic-input/generic-input.component.html" }) export class NgParamMinComponent extends GenericInputComponent { - constructor(private intlService: InternationalisationService) { - super(); + constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) { + super(cdRef); } /** diff --git a/src/app/components/param-values/ngparam-step.component.ts b/src/app/components/param-values/ngparam-step.component.ts index 3825d5280be572d00466d63928d8c399412533d4..a1467d2953dfa1783dce05e5dc8568eb863c8372 100644 --- a/src/app/components/param-values/ngparam-step.component.ts +++ b/src/app/components/param-values/ngparam-step.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from "@angular/core"; +import { Component, Input, ChangeDetectorRef } from "@angular/core"; import { NumericalString } from "jalhyd"; @@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam"; templateUrl: "../generic-input/generic-input.component.html" }) export class NgParamStepComponent extends GenericInputComponent { - constructor(private intlService: InternationalisationService) { - super(); + constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) { + super(cdRef); } /** diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index 8ec032838f757a9982acd1939fafc05a476ed9ee..ff493337bb98d38f71e9f800bae5dbc9cc2aba63 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -317,10 +317,10 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec this._param.valueMode = next; } - /** - * appelé au 1er affichage du composant + /** + * appelé quand les @Input changent */ - protected afterFirstViewChecked() { + ngOnChanges() { if (this.isMinMax) this._doInitMinmax = true; else diff --git a/src/app/components/param-values/value-list.component.ts b/src/app/components/param-values/value-list.component.ts index 2286d317e256af2e408c6495f276d1ea9d81bd53..86e37fe7c4bca6a176c8def0583e2def7b57a81d 100644 --- a/src/app/components/param-values/value-list.component.ts +++ b/src/app/components/param-values/value-list.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from "@angular/core"; +import { Component, Input, ChangeDetectorRef } from "@angular/core"; import { GenericInputComponent } from "../generic-input/generic-input.component"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; @@ -10,8 +10,8 @@ import { Message } from "jalhyd"; templateUrl: "../generic-input/generic-input.component.html" }) export class ValueListComponent extends GenericInputComponent { - constructor(private intlService: InternationalisationService) { - super(); + constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) { + super(cdRef); } /**