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' ;
22import { getStyle } from '@coreui/utils' ;
33import { ChartjsComponent } from '@coreui/angular-chartjs' ;
44import { RouterLink } from '@angular/router' ;
55import { 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' ;
718
819@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 ]
1424} )
1525export class WidgetsDropdownComponent implements OnInit , AfterContentInit {
1626 private changeDetectorRef = inject ( ChangeDetectorRef ) ;
1727
18-
1928 data : any [ ] = [ ] ;
2029 options : any [ ] = [ ] ;
2130 labels = [
@@ -77,7 +86,7 @@ export class WidgetsDropdownComponent implements OnInit, AfterContentInit {
7786 scales : {
7887 x : {
7988 border : {
80- display : false ,
89+ display : false
8190 } ,
8291 grid : {
8392 display : false ,
@@ -169,15 +178,15 @@ export class WidgetsDropdownComponent implements OnInit, AfterContentInit {
169178}
170179
171180@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 ]
175184} )
176185export class ChartSample implements AfterViewInit {
177186
178187 constructor ( ) { }
179188
180- @ ViewChild ( 'chart' ) chartComponent ! : ChartjsComponent ;
189+ readonly chartComponent = viewChild . required < ChartjsComponent > ( 'chart' ) ;
181190
182191 colors = {
183192 label : 'My dataset' ,
@@ -228,7 +237,7 @@ export class ChartSample implements AfterViewInit {
228237 const newData = [ 42 , 88 , 42 , 66 , 77 ] ;
229238 let { datasets, labels } = { ...this . data } ;
230239 // @ts -ignore
231- const before = this . chartComponent ?. chart ?. data . datasets . length ;
240+ const before = this . chartComponent ( ) ?. chart ?. data . datasets . length ;
232241 console . log ( 'before' , before ) ;
233242 // console.log('datasets, labels', datasets, labels)
234243 // @ts -ignore
@@ -245,7 +254,7 @@ export class ChartSample implements AfterViewInit {
245254 // console.log('datasets, labels', { datasets, labels } = {...this.data})
246255 // @ts -ignore
247256 setTimeout ( ( ) => {
248- const after = this . chartComponent ?. chart ?. data . datasets . length ;
257+ const after = this . chartComponent ( ) ?. chart ?. data . datasets . length ;
249258 console . log ( 'after' , after ) ;
250259 } ) ;
251260 } , 5000 ) ;
0 commit comments