I am attempting to convert the offset value for a time object in the URI, which is stored in an observable object.
The issue I am encountering is:
ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '2023-11-20T00:00:00-05:00'. Current value: '2023-11-20T00:00:00-06:00'. Find more at https://angular.io/errors/NG0100
HTML code:
<ng-container *ngFor="let app of siteGroup[site.name]">
<ng-template #tipContent1>
<div class="tooltip-container">
{{site.name}} - {{app.description}}
</div>
</ng-template>
<a class="clickable" [ngbTooltip]="tipContent1" [openDelay]="200" container="body"
ngbDropdownItem routerLink="/site/{{site.name}}/{{app.name}}"
[queryParams]="{caseName: routeParams.caseName, windowSize: routeParams.windowSize, startTime: changeCurrentParamTimezoneStartTime() , endTime: changeCurrentParamTimezoneEndtime(), equipmentTypes: routeParams.equipmentTypes}"
(keydown.enter)="onEnter($event)">
{{app.name}}
</a>
</ng-container>
The function that needs to be modified if the time object exists is
changeCurrentParamTimezoneStartTime(){
//initial value could be 2023-11-20T00:00:00-05:00
if(this.routeParams.startTime){
this.routeParams.startTime = this.routeParams.startTime.slice(0,10);
this.routeParams.startTime = moment(this.routeParams.startTime)
.utcOffset(parseFloat(this.timeZoneOffset), true)
.startOf('day')
.format();
//and the return value i want is 2023-11-20T00:00:00-06:00
return this.routeParams.startTime;
}
else{
return;
}
}
changeCurrentParamTimezoneEndtime(){
// return null
if( this.routeParams.endTime){
this.routeParams.endTime = this.routeParams.endTime.slice(0,10);
this.routeParams.endTime = this.routeParams.endTime = moment(this.routeParams.endTime)
.utcOffset(parseFloat(this.timeZoneOffset), true)
.endOf('day')
.format();
return this.routeParams.endTime;
}
else{
return;
}
}
and the observable object is initialized in ngOnInit
this.navigationService.routeParams.subscribe(routeParams => this.routeParams = routeParams);
When I log the value, I can see that it is updated but the URI does not reflect the changes in the offset value.