1
- import { NgFor } from '@angular/common' ;
2
- import { ChangeDetectorRef , Component , VERSION , inject } from '@angular/core' ;
1
+ import { ApplicationRef , Component , VERSION , inject } from '@angular/core' ;
3
2
4
3
interface Data {
5
4
id : number ;
@@ -12,11 +11,10 @@ const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie"
12
11
13
12
@Component ( {
14
13
selector : 'app-root' ,
15
- imports : [ NgFor ] ,
16
14
templateUrl : './app.component.html'
17
15
} )
18
16
export class AppComponent {
19
- private cdr = inject ( ChangeDetectorRef ) ;
17
+ private applicationRef = inject ( ApplicationRef ) ;
20
18
21
19
data : Array < Data > = [ ] ;
22
20
selected ?: number = undefined ;
@@ -44,7 +42,7 @@ export class AppComponent {
44
42
select ( item : Data , event : Event ) {
45
43
event . preventDefault ( ) ;
46
44
this . selected = item . id ;
47
- this . cdr . detectChanges ( ) ;
45
+ this . applicationRef . tick ( ) ;
48
46
}
49
47
50
48
delete ( item : Data , event : Event ) {
@@ -55,41 +53,41 @@ export class AppComponent {
55
53
break ;
56
54
}
57
55
}
58
- this . cdr . detectChanges ( ) ;
56
+ this . applicationRef . tick ( ) ;
59
57
}
60
58
61
59
run ( ) {
62
60
this . data = this . buildData ( ) ;
63
- this . cdr . detectChanges ( ) ;
61
+ this . applicationRef . tick ( ) ;
64
62
}
65
63
66
64
add ( ) {
67
65
this . data = this . data . concat ( this . buildData ( 1000 ) ) ;
68
- this . cdr . detectChanges ( ) ;
66
+ this . applicationRef . tick ( ) ;
69
67
}
70
68
71
69
update ( ) {
72
70
for ( let i = 0 ; i < this . data . length ; i += 10 ) {
73
71
this . data [ i ] . label += ' !!!' ;
74
72
}
75
- this . cdr . detectChanges ( ) ;
73
+ this . applicationRef . tick ( ) ;
76
74
}
77
75
runLots ( ) {
78
76
this . data = this . buildData ( 10000 ) ;
79
77
this . selected = undefined ;
80
- this . cdr . detectChanges ( ) ;
78
+ this . applicationRef . tick ( ) ;
81
79
}
82
80
clear ( ) {
83
81
this . data = [ ] ;
84
82
this . selected = undefined ;
85
- this . cdr . detectChanges ( ) ;
83
+ this . applicationRef . tick ( ) ;
86
84
}
87
85
swapRows ( ) {
88
86
if ( this . data . length > 998 ) {
89
87
var a = this . data [ 1 ] ;
90
88
this . data [ 1 ] = this . data [ 998 ] ;
91
89
this . data [ 998 ] = a ;
92
90
}
93
- this . cdr . detectChanges ( ) ;
91
+ this . applicationRef . tick ( ) ;
94
92
}
95
93
}
0 commit comments