diff --git a/src/dev-app/performance/performance-demo.ts b/src/dev-app/performance/performance-demo.ts index a066adcee10a..1bc1d5b8bec7 100644 --- a/src/dev-app/performance/performance-demo.ts +++ b/src/dev-app/performance/performance-demo.ts @@ -6,7 +6,14 @@ * found in the LICENSE file at https://angular.io/license */ -import {AfterViewInit, Component, NgZone, ViewChild} from '@angular/core'; +import { + afterNextRender, + AfterViewInit, + Component, + inject, + Injector, + ViewChild, +} from '@angular/core'; import {CommonModule} from '@angular/common'; import {FormsModule} from '@angular/forms'; @@ -19,8 +26,6 @@ import {MatPaginator, MatPaginatorModule} from '@angular/material/paginator'; import {MatSelectModule} from '@angular/material/select'; import {MatTableDataSource, MatTableModule} from '@angular/material/table'; -import {take} from 'rxjs/operators'; - @Component({ selector: 'performance-demo', templateUrl: 'performance-demo.html', @@ -67,6 +72,8 @@ export class PerformanceDemo implements AfterViewInit { /** Used in an `@for` to render the desired number of comonents. */ componentArray = [].constructor(this.componentCount); + private _injector = inject(Injector); + /** The standard deviation of the recorded samples. */ get stdev(): number | undefined { if (!this.allSamples.length) { @@ -86,8 +93,6 @@ export class PerformanceDemo implements AfterViewInit { return this.allSamples.reduce((a, b) => a + b) / this.allSamples.length; } - constructor(private _ngZone: NgZone) {} - @ViewChild(MatPaginator) paginator?: MatPaginator; ngAfterViewInit() { @@ -131,11 +136,14 @@ export class PerformanceDemo implements AfterViewInit { setTimeout(() => { this.show = true; const start = performance.now(); - this._ngZone.onStable.pipe(take(1)).subscribe(() => { - const end = performance.now(); - this.show = false; - res(end - start); - }); + afterNextRender( + () => { + const end = performance.now(); + this.show = false; + res(end - start); + }, + {injector: this._injector}, + ); }); }); }