Skip to content
Snippets Groups Projects
Commit 7c2d6e8b authored by francois.grand's avatar francois.grand
Browse files

correction des messages console 'ExpressionChangedAfterItHasBeenCheck'

parent 54fd3062
No related branches found
No related tags found
1 merge request!12Resolve "Ajout de la calculette "Ouvrages hydrauliques""
Showing with 49 additions and 31 deletions
...@@ -44,8 +44,8 @@ export class NgBaseParam extends Observable { ...@@ -44,8 +44,8 @@ export class NgBaseParam extends Observable {
templateUrl: "../generic-input/generic-input.component.html", templateUrl: "../generic-input/generic-input.component.html",
}) })
export class BaseParamInputComponent extends GenericInputComponent { export class BaseParamInputComponent extends GenericInputComponent {
constructor(private intlService: InternationalisationService) { constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) {
super(); super(cdRef);
} }
/** /**
......
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 * true après le 1er affichage du composant
*/ */
...@@ -32,8 +32,12 @@ export abstract class BaseComponent implements AfterViewChecked { ...@@ -32,8 +32,12 @@ export abstract class BaseComponent implements AfterViewChecked {
} }
} }
public ngOnChanges() {
}
/** /**
* appelé une fois, après l'affichage complet du composant * appelé une fois, après l'affichage complet du composant
*/ */
protected abstract afterFirstViewChecked(); protected afterFirstViewChecked() {
}
} }
\ No newline at end of file
import { Input, Output, EventEmitter } from "@angular/core"; import { Input, Output, EventEmitter, ChangeDetectorRef } from "@angular/core";
import { BaseComponent } from "../base/base.component"; import { BaseComponent } from "../base/base.component";
...@@ -79,6 +79,10 @@ export abstract class GenericInputComponent extends BaseComponent { ...@@ -79,6 +79,10 @@ export abstract class GenericInputComponent extends BaseComponent {
*/ */
private _errorMessageModel: string; private _errorMessageModel: string;
constructor(private cdRef: ChangeDetectorRef) {
super();
}
private get isDisabled(): boolean { private get isDisabled(): boolean {
return this._inputDisabled; return this._inputDisabled;
} }
...@@ -90,6 +94,14 @@ export abstract class GenericInputComponent extends BaseComponent { ...@@ -90,6 +94,14 @@ export abstract class GenericInputComponent extends BaseComponent {
this.onChange.emit({ "action": "valid", "value": this.isValid }); 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) * calcul de la validité globale du composant (UI+modèle)
*/ */
...@@ -107,6 +119,7 @@ export abstract class GenericInputComponent extends BaseComponent { ...@@ -107,6 +119,7 @@ export abstract class GenericInputComponent extends BaseComponent {
private validateUI() { private validateUI() {
let { isValid, message } = this.validateUIValue(this._uiValue); let { isValid, message } = this.validateUIValue(this._uiValue);
this._errorMessageUI = message; this._errorMessageUI = message;
this.detectChanges();
this.setUIValid(isValid); this.setUIValid(isValid);
return isValid; return isValid;
} }
...@@ -121,6 +134,7 @@ export abstract class GenericInputComponent extends BaseComponent { ...@@ -121,6 +134,7 @@ export abstract class GenericInputComponent extends BaseComponent {
private validateModel() { private validateModel() {
let { isValid, message } = this.validateModelValue(this.getModelValue()); let { isValid, message } = this.validateModelValue(this.getModelValue());
this._errorMessageModel = message; this._errorMessageModel = message;
this.detectChanges();
this.setModelValid(isValid); this.setModelValid(isValid);
} }
...@@ -162,6 +176,7 @@ export abstract class GenericInputComponent extends BaseComponent { ...@@ -162,6 +176,7 @@ export abstract class GenericInputComponent extends BaseComponent {
this._model = v; this._model = v;
this.afterSetModel(); this.afterSetModel();
this.updateAll(); this.updateAll();
this.detectChanges();
} }
/** /**
...@@ -192,10 +207,9 @@ export abstract class GenericInputComponent extends BaseComponent { ...@@ -192,10 +207,9 @@ export abstract class GenericInputComponent extends BaseComponent {
} }
/** /**
* appelé après le 1er affichage du composant * appelé quand les @Input changent
* @see BaseComponent
*/ */
protected afterFirstViewChecked() { public ngOnChanges() {
this.updateAll(); this.updateAll();
} }
......
...@@ -28,13 +28,13 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse ...@@ -28,13 +28,13 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse
*/ */
private _tmp: number; private _tmp: number;
constructor(private intlService: InternationalisationService) { constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) {
super(); super(cdRef);
} }
/** /**
* appelé avant le changement de modèle * appelé avant le changement de modèle
*/ */
protected beforeSetModel() { protected beforeSetModel() {
if (this._paramDef != undefined) if (this._paramDef != undefined)
this._paramDef.removeObserver(this); this._paramDef.removeObserver(this);
......
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 { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
import { NgParameter, ParamRadioConfig } from "../../formulaire/ngparam"; import { NgParameter, ParamRadioConfig } from "../../formulaire/ngparam";
...@@ -25,7 +25,7 @@ import { FormulaireService } from "../../services/formulaire/formulaire.service" ...@@ -25,7 +25,7 @@ import { FormulaireService } from "../../services/formulaire/formulaire.service"
}` }`
] ]
}) })
export class ParamFieldLineComponent implements AfterViewChecked { export class ParamFieldLineComponent implements OnChanges {
@Input("param") @Input("param")
private _param: NgParameter; private _param: NgParameter;
...@@ -257,7 +257,7 @@ export class ParamFieldLineComponent implements AfterViewChecked { ...@@ -257,7 +257,7 @@ export class ParamFieldLineComponent implements AfterViewChecked {
this.emitValidity() this.emitValidity()
} }
public ngAfterViewChecked() { public ngOnChanges() {
this._ngParamInputComponent.model = this._param; this._ngParamInputComponent.model = this._param;
this._ngParamInputComponent.showError = this.isRadioFixChecked; this._ngParamInputComponent.showError = this.isRadioFixChecked;
} }
......
import { Component, Input } from "@angular/core"; import { Component, Input, ChangeDetectorRef } from "@angular/core";
import { NumericalString } from "jalhyd"; import { NumericalString } from "jalhyd";
...@@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam"; ...@@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam";
templateUrl: "../generic-input/generic-input.component.html" templateUrl: "../generic-input/generic-input.component.html"
}) })
export class NgParamMaxComponent extends GenericInputComponent { export class NgParamMaxComponent extends GenericInputComponent {
constructor(private intlService: InternationalisationService) { constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) {
super(); super(cdRef);
} }
/** /**
......
import { Component, Input } from "@angular/core"; import { Component, Input, ChangeDetectorRef } from "@angular/core";
import { NumericalString } from "jalhyd"; import { NumericalString } from "jalhyd";
...@@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam"; ...@@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam";
templateUrl: "../generic-input/generic-input.component.html" templateUrl: "../generic-input/generic-input.component.html"
}) })
export class NgParamMinComponent extends GenericInputComponent { export class NgParamMinComponent extends GenericInputComponent {
constructor(private intlService: InternationalisationService) { constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) {
super(); super(cdRef);
} }
/** /**
......
import { Component, Input } from "@angular/core"; import { Component, Input, ChangeDetectorRef } from "@angular/core";
import { NumericalString } from "jalhyd"; import { NumericalString } from "jalhyd";
...@@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam"; ...@@ -11,8 +11,8 @@ import { NgParameter } from "../../formulaire/ngparam";
templateUrl: "../generic-input/generic-input.component.html" templateUrl: "../generic-input/generic-input.component.html"
}) })
export class NgParamStepComponent extends GenericInputComponent { export class NgParamStepComponent extends GenericInputComponent {
constructor(private intlService: InternationalisationService) { constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) {
super(); super(cdRef);
} }
/** /**
......
...@@ -317,10 +317,10 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec ...@@ -317,10 +317,10 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec
this._param.valueMode = next; this._param.valueMode = next;
} }
/** /**
* appelé au 1er affichage du composant * appelé quand les @Input changent
*/ */
protected afterFirstViewChecked() { ngOnChanges() {
if (this.isMinMax) if (this.isMinMax)
this._doInitMinmax = true; this._doInitMinmax = true;
else else
......
import { Component, Input } from "@angular/core"; import { Component, Input, ChangeDetectorRef } from "@angular/core";
import { GenericInputComponent } from "../generic-input/generic-input.component"; import { GenericInputComponent } from "../generic-input/generic-input.component";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
...@@ -10,8 +10,8 @@ import { Message } from "jalhyd"; ...@@ -10,8 +10,8 @@ import { Message } from "jalhyd";
templateUrl: "../generic-input/generic-input.component.html" templateUrl: "../generic-input/generic-input.component.html"
}) })
export class ValueListComponent extends GenericInputComponent { export class ValueListComponent extends GenericInputComponent {
constructor(private intlService: InternationalisationService) { constructor(private intlService: InternationalisationService, cdRef: ChangeDetectorRef) {
super(); super(cdRef);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment