1
- import { AfterContentInit , AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , OnInit , ViewChild , inject } from '@angular/core' ;
1
+ import { AfterContentInit , AfterViewInit , ChangeDetectorRef , Component , inject , OnInit , viewChild } from '@angular/core' ;
2
2
import { getStyle } from '@coreui/utils' ;
3
3
import { ChartjsComponent } from '@coreui/angular-chartjs' ;
4
4
import { RouterLink } from '@angular/router' ;
5
5
import { IconDirective } from '@coreui/icons-angular' ;
6
- import { RowComponent , ColComponent , WidgetStatAComponent , TemplateIdDirective , ThemeDirective , DropdownComponent , ButtonDirective , DropdownToggleDirective , DropdownMenuDirective , DropdownItemDirective , DropdownDividerDirective } from '@coreui/angular' ;
6
+ import {
7
+ ButtonDirective ,
8
+ ColComponent ,
9
+ DropdownComponent ,
10
+ DropdownDividerDirective ,
11
+ DropdownItemDirective ,
12
+ DropdownMenuDirective ,
13
+ DropdownToggleDirective ,
14
+ RowComponent ,
15
+ TemplateIdDirective ,
16
+ WidgetStatAComponent
17
+ } from '@coreui/angular' ;
7
18
8
19
@Component ( {
9
- selector : 'app-widgets-dropdown' ,
10
- templateUrl : './widgets-dropdown.component.html' ,
11
- styleUrls : [ './widgets-dropdown.component.scss' ] ,
12
- changeDetection : ChangeDetectionStrategy . Default ,
13
- imports : [ RowComponent , ColComponent , WidgetStatAComponent , TemplateIdDirective , IconDirective , ThemeDirective , DropdownComponent , ButtonDirective , DropdownToggleDirective , DropdownMenuDirective , DropdownItemDirective , RouterLink , DropdownDividerDirective , ChartjsComponent ]
20
+ selector : 'app-widgets-dropdown' ,
21
+ templateUrl : './widgets-dropdown.component.html' ,
22
+ styleUrls : [ './widgets-dropdown.component.scss' ] ,
23
+ imports : [ RowComponent , ColComponent , WidgetStatAComponent , TemplateIdDirective , IconDirective , DropdownComponent , ButtonDirective , DropdownToggleDirective , DropdownMenuDirective , DropdownItemDirective , RouterLink , DropdownDividerDirective , ChartjsComponent ]
14
24
} )
15
25
export class WidgetsDropdownComponent implements OnInit , AfterContentInit {
16
26
private changeDetectorRef = inject ( ChangeDetectorRef ) ;
17
27
18
-
19
28
data : any [ ] = [ ] ;
20
29
options : any [ ] = [ ] ;
21
30
labels = [
@@ -77,7 +86,7 @@ export class WidgetsDropdownComponent implements OnInit, AfterContentInit {
77
86
scales : {
78
87
x : {
79
88
border : {
80
- display : false ,
89
+ display : false
81
90
} ,
82
91
grid : {
83
92
display : false ,
@@ -169,15 +178,15 @@ export class WidgetsDropdownComponent implements OnInit, AfterContentInit {
169
178
}
170
179
171
180
@Component ( {
172
- selector : 'app-chart-sample' ,
173
- template : '<c-chart type="line" [data]="data" [options]="options" width="300" #chart></c-chart>' ,
174
- imports : [ ChartjsComponent ]
181
+ selector : 'app-chart-sample' ,
182
+ template : '<c-chart type="line" [data]="data" [options]="options" width="300" #chart></c-chart>' ,
183
+ imports : [ ChartjsComponent ]
175
184
} )
176
185
export class ChartSample implements AfterViewInit {
177
186
178
187
constructor ( ) { }
179
188
180
- @ ViewChild ( 'chart' ) chartComponent ! : ChartjsComponent ;
189
+ readonly chartComponent = viewChild . required < ChartjsComponent > ( 'chart' ) ;
181
190
182
191
colors = {
183
192
label : 'My dataset' ,
@@ -228,7 +237,7 @@ export class ChartSample implements AfterViewInit {
228
237
const newData = [ 42 , 88 , 42 , 66 , 77 ] ;
229
238
let { datasets, labels } = { ...this . data } ;
230
239
// @ts -ignore
231
- const before = this . chartComponent ?. chart ?. data . datasets . length ;
240
+ const before = this . chartComponent ( ) ?. chart ?. data . datasets . length ;
232
241
console . log ( 'before' , before ) ;
233
242
// console.log('datasets, labels', datasets, labels)
234
243
// @ts -ignore
@@ -245,7 +254,7 @@ export class ChartSample implements AfterViewInit {
245
254
// console.log('datasets, labels', { datasets, labels } = {...this.data})
246
255
// @ts -ignore
247
256
setTimeout ( ( ) => {
248
- const after = this . chartComponent ?. chart ?. data . datasets . length ;
257
+ const after = this . chartComponent ( ) ?. chart ?. data . datasets . length ;
249
258
console . log ( 'after' , after ) ;
250
259
} ) ;
251
260
} , 5000 ) ;
0 commit comments