6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { AfterViewInit , Component , NgZone , ViewChild } from '@angular/core' ;
9
+ import {
10
+ afterNextRender ,
11
+ AfterViewInit ,
12
+ Component ,
13
+ inject ,
14
+ Injector ,
15
+ ViewChild ,
16
+ } from '@angular/core' ;
10
17
import { CommonModule } from '@angular/common' ;
11
18
import { FormsModule } from '@angular/forms' ;
12
19
@@ -19,8 +26,6 @@ import {MatPaginator, MatPaginatorModule} from '@angular/material/paginator';
19
26
import { MatSelectModule } from '@angular/material/select' ;
20
27
import { MatTableDataSource , MatTableModule } from '@angular/material/table' ;
21
28
22
- import { take } from 'rxjs/operators' ;
23
-
24
29
@Component ( {
25
30
selector : 'performance-demo' ,
26
31
templateUrl : 'performance-demo.html' ,
@@ -67,6 +72,8 @@ export class PerformanceDemo implements AfterViewInit {
67
72
/** Used in an `@for` to render the desired number of comonents. */
68
73
componentArray = [ ] . constructor ( this . componentCount ) ;
69
74
75
+ private _injector = inject ( Injector ) ;
76
+
70
77
/** The standard deviation of the recorded samples. */
71
78
get stdev ( ) : number | undefined {
72
79
if ( ! this . allSamples . length ) {
@@ -86,8 +93,6 @@ export class PerformanceDemo implements AfterViewInit {
86
93
return this . allSamples . reduce ( ( a , b ) => a + b ) / this . allSamples . length ;
87
94
}
88
95
89
- constructor ( private _ngZone : NgZone ) { }
90
-
91
96
@ViewChild ( MatPaginator ) paginator ?: MatPaginator ;
92
97
93
98
ngAfterViewInit ( ) {
@@ -131,11 +136,14 @@ export class PerformanceDemo implements AfterViewInit {
131
136
setTimeout ( ( ) => {
132
137
this . show = true ;
133
138
const start = performance . now ( ) ;
134
- this . _ngZone . onStable . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
135
- const end = performance . now ( ) ;
136
- this . show = false ;
137
- res ( end - start ) ;
138
- } ) ;
139
+ afterNextRender (
140
+ ( ) => {
141
+ const end = performance . now ( ) ;
142
+ this . show = false ;
143
+ res ( end - start ) ;
144
+ } ,
145
+ { injector : this . _injector } ,
146
+ ) ;
139
147
} ) ;
140
148
} ) ;
141
149
}
0 commit comments