Fix ExpressionChangedAfterItHasBeenCheckedError

This commit is contained in:
shamoon
2026-02-08 23:17:40 -08:00
parent 9b0e4756b3
commit e29a393743

View File

@@ -1,5 +1,7 @@
import { NgComponentOutlet } from '@angular/common' import { NgComponentOutlet } from '@angular/common'
import { import {
AfterViewChecked,
ChangeDetectorRef,
Component, Component,
inject, inject,
OnDestroy, OnDestroy,
@@ -65,10 +67,13 @@ interface DocumentAttributesSection {
ClearableBadgeComponent, ClearableBadgeComponent,
], ],
}) })
export class DocumentAttributesComponent implements OnInit, OnDestroy { export class DocumentAttributesComponent
implements OnInit, OnDestroy, AfterViewChecked
{
private readonly permissionsService = inject(PermissionsService) private readonly permissionsService = inject(PermissionsService)
private readonly activatedRoute = inject(ActivatedRoute) private readonly activatedRoute = inject(ActivatedRoute)
private readonly router = inject(Router) private readonly router = inject(Router)
private readonly cdr = inject(ChangeDetectorRef)
private readonly unsubscribeNotifier = new Subject<void>() private readonly unsubscribeNotifier = new Subject<void>()
protected readonly PermissionAction = PermissionAction protected readonly PermissionAction = PermissionAction
@@ -130,6 +135,8 @@ export class DocumentAttributesComponent implements OnInit, OnDestroy {
@ViewChild('activeOutlet', { read: NgComponentOutlet }) @ViewChild('activeOutlet', { read: NgComponentOutlet })
private activeOutlet?: NgComponentOutlet private activeOutlet?: NgComponentOutlet
private lastHeaderLoading: boolean
activeNavID: number = null activeNavID: number = null
get visibleSections(): DocumentAttributesSection[] { get visibleSections(): DocumentAttributesSection[] {
@@ -207,6 +214,14 @@ export class DocumentAttributesComponent implements OnInit, OnDestroy {
this.unsubscribeNotifier.complete() this.unsubscribeNotifier.complete()
} }
ngAfterViewChecked(): void {
const current = this.activeHeaderLoading
if (this.lastHeaderLoading !== current) {
this.lastHeaderLoading = current
this.cdr.detectChanges()
}
}
onNavChange(navChangeEvent: NgbNavChangeEvent): void { onNavChange(navChangeEvent: NgbNavChangeEvent): void {
const nextSection = this.getSectionForNavID(navChangeEvent.nextId) const nextSection = this.getSectionForNavID(navChangeEvent.nextId)
if (!nextSection) { if (!nextSection) {