From 7edd4d27bc78bbdee705e5eda22639a5e68f5420 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Fri, 26 Jan 2018 16:26:10 +0100 Subject: [PATCH] =?UTF-8?q?correction=20du=20message=20d'erreur=20console?= =?UTF-8?q?=20ExpressionChangedAfterItHasBeenCheckedError=20concernant=20l?= =?UTF-8?q?a=20classe=20CSS=20de=20la=20calculette=20active=20dans=20la=20?= =?UTF-8?q?barre=20de=20navigation=20sup=C3=A9rieure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.component.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 2c3ab0eee..6c63ed5c2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,7 +1,7 @@ -import { Component, ApplicationRef } from '@angular/core'; -//import { Component, ChangeDetectorRef, ApplicationRef, AfterViewChecked } from '@angular/core'; +import { Component, ApplicationRef, OnInit, OnDestroy } from '@angular/core'; //import { MdDialog } from '@angular/material'; import { Router } from '@angular/router'; +import { setTimeout } from 'timers'; import { ComputeNodeType, ComputeNode } from 'jalhyd'; @@ -12,7 +12,6 @@ import { ErrorService } from './services/error/error.service'; // import { AlertDialog } from './components/alert-dialog/alert-dialog.component'; import { FormulaireService } from './services/formulaire/formulaire.service'; import { FormulaireDefinition, CalculatorType } from './formulaire/formulaire-definition'; -import { OnInit, OnDestroy } from '@angular/core/src/metadata/lifecycle_hooks'; @Component({ @@ -25,6 +24,12 @@ export class AppComponent implements OnInit, OnDestroy, Observer { private _calculators: any[] = []; + /** + * id du formulaire courant + * on utilise pas directement FormulaireService.currentFormId pour éviter l'erreur ExpressionChangedAfterItHasBeenCheckedError + */ + private _currentFormId: number; + // constructor(private intlService: InternationalisationService, private appRef: ApplicationRef, private dialog: MdDialog, private errorService: ErrorService) { } constructor(private intlService: InternationalisationService, private appRef: ApplicationRef, @@ -115,6 +120,16 @@ export class AppComponent implements OnInit, OnDestroy, Observer { this.toList(); break; + case "currentFormChanged": + /* + utilisation de setTimeout() pour éviter le message console ExpressionChangedAfterItHasBeenCheckedError + relatif au getter getHighlightClass() (qui change de valeur quand le formulaire courant change) + */ + setTimeout(() => { + this._currentFormId = data["formId"]; + }, 1); + break; + case "closeForm": const form: FormulaireDefinition = data["form"]; this.closeCalculator(form); @@ -182,8 +197,10 @@ export class AppComponent implements OnInit, OnDestroy, Observer { // MAJ affichage - if (newId == -1) + if (newId == -1) { this.toList(); + this._currentFormId = -1; + } else this.toCalc(newId); } @@ -197,7 +214,7 @@ export class AppComponent implements OnInit, OnDestroy, Observer { } private getHighlightClass(uid: number) { - return uid == this.formulaireService.currentFormId ? "blue darken-2" : ""; + return uid == this._currentFormId ? "blue darken-2" : ""; } // flag d'affichage des repères des colonnes Bootstrap : uniquement en mode dev -- GitLab