Skip to content

Commit e999724

Browse files
committed
refactor: migrate to inject function (remove constructor-based dependency injection)
1 parent 677497e commit e999724

File tree

12 files changed

+40
-68
lines changed

12 files changed

+40
-68
lines changed

src/app/views/base/accordion/accordions.component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { DomSanitizer } from '@angular/platform-browser';
33
import { RowComponent, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, AccordionComponent, AccordionItemComponent, TemplateIdDirective, AccordionButtonDirective, BgColorDirective } from '@coreui/angular';
44
import { DocsExampleComponent } from '@docs-components/public-api';
@@ -10,12 +10,10 @@ import { DocsExampleComponent } from '@docs-components/public-api';
1010
imports: [RowComponent, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, DocsExampleComponent, AccordionComponent, AccordionItemComponent, TemplateIdDirective, AccordionButtonDirective, BgColorDirective]
1111
})
1212
export class AccordionsComponent {
13+
private sanitizer = inject(DomSanitizer);
1314

14-
items = [1, 2, 3, 4];
1515

16-
constructor(
17-
private sanitizer: DomSanitizer
18-
) { }
16+
items = [1, 2, 3, 4];
1917

2018
getAccordionBodyText(value: string|number) {
2119
const textSample = `

src/app/views/base/carousels/carousels.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, signal } from '@angular/core';
1+
import { Component, signal, inject } from '@angular/core';
22
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
33
import { DocsExampleComponent } from '@docs-components/public-api';
44
import {
@@ -27,13 +27,17 @@ export type Slide = { id: number, src: SafeUrl | string, title: string, subtitle
2727
// providers: [{ provide: CarouselConfig, useClass: CarouselCustomConfig }]
2828
})
2929
export class CarouselsComponent {
30+
private domSanitizer = inject(DomSanitizer);
31+
3032

3133

3234
readonly imageSrc: string[] = ['assets/images/angular.jpg', 'assets/images/react.jpg', 'assets/images/vue.jpg', 'https://picsum.photos/id/1/800/400', 'https://picsum.photos/id/1026/800/400', 'https://picsum.photos/id/1031/800/400'];
3335
readonly slidesLight: string[] = ['data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22400%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20400%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_1607923e7e2%20text%20%7B%20fill%3A%23AAA%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A40pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_1607923e7e2%22%3E%3Crect%20width%3D%22800%22%20height%3D%22400%22%20fill%3D%22%23F5F5F5%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22285.9296875%22%20y%3D%22217.75625%22%3EFirst%20slide%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E', 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22400%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20400%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_15ba800aa20%20text%20%7B%20fill%3A%23BBB%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A40pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_15ba800aa20%22%3E%3Crect%20width%3D%22800%22%20height%3D%22400%22%20fill%3D%22%23EEE%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22247.3203125%22%20y%3D%22218.3%22%3ESecond%20slide%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E', 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22400%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20400%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_15ba800aa21%20text%20%7B%20fill%3A%23999%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A40pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_15ba800aa21%22%3E%3Crect%20width%3D%22800%22%20height%3D%22400%22%20fill%3D%22%23E5E5E5%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22277%22%20y%3D%22218.3%22%3EThird%20slide%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E'];
3436
readonly slides: Slide[][] = [];
3537

36-
constructor(private domSanitizer: DomSanitizer) {
38+
constructor() {
39+
const domSanitizer = this.domSanitizer;
40+
3741
this.slides[0] = [{
3842
id: 0,
3943
src: domSanitizer.bypassSecurityTrustUrl(this.imageSrc[0]),

src/app/views/base/list-groups/list-groups.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { UntypedFormBuilder, ReactiveFormsModule } from '@angular/forms';
33
import { DocsExampleComponent } from '@docs-components/public-api';
44
import { RowComponent, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, ListGroupDirective, ListGroupItemDirective, BadgeComponent, FormDirective, FormCheckComponent, FormCheckInputDirective, FormCheckLabelDirective, ButtonDirective } from '@coreui/angular';
@@ -10,10 +10,8 @@ import { RowComponent, ColComponent, TextColorDirective, CardComponent, CardHead
1010
imports: [RowComponent, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, DocsExampleComponent, ListGroupDirective, ListGroupItemDirective, BadgeComponent, ReactiveFormsModule, FormDirective, FormCheckComponent, FormCheckInputDirective, FormCheckLabelDirective, ButtonDirective]
1111
})
1212
export class ListGroupsComponent {
13+
private formBuilder = inject(UntypedFormBuilder);
1314

14-
constructor(
15-
private formBuilder: UntypedFormBuilder
16-
) { }
1715

1816
readonly breakpoints: (string | boolean)[] = [true, 'sm', 'md', 'lg', 'xl', 'xxl'];
1917
readonly colors: string[] = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'];

src/app/views/buttons/button-groups/button-groups.component.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, ReactiveFormsModule } from '@angular/forms';
33
import { RouterLink } from '@angular/router';
44
import { DocsExampleComponent } from '@docs-components/public-api';
@@ -11,6 +11,8 @@ import { RowComponent, ColComponent, TextColorDirective, CardComponent, CardHead
1111
imports: [RowComponent, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, DocsExampleComponent, ButtonGroupComponent, ButtonDirective, RouterLink, ReactiveFormsModule, FormCheckLabelDirective, ButtonToolbarComponent, InputGroupComponent, InputGroupTextDirective, FormControlDirective, ThemeDirective, DropdownComponent, DropdownToggleDirective, DropdownMenuDirective, DropdownItemDirective, DropdownDividerDirective]
1212
})
1313
export class ButtonGroupsComponent {
14+
private formBuilder = inject(UntypedFormBuilder);
15+
1416

1517
formCheck1 = this.formBuilder.group({
1618
checkbox1: false,
@@ -21,10 +23,6 @@ export class ButtonGroupsComponent {
2123
radio1: new UntypedFormControl('Radio1')
2224
});
2325

24-
constructor(
25-
private formBuilder: UntypedFormBuilder
26-
) { }
27-
2826
setCheckBoxValue(controlName: string) {
2927
const prevValue = this.formCheck1.get(controlName)?.value;
3028
const value = this.formCheck1.value;

src/app/views/forms/checks-radios/checks-radios.component.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { FormControl, UntypedFormBuilder, ReactiveFormsModule } from '@angular/forms';
33
import { DocsExampleComponent } from '@docs-components/public-api';
44
import { RowComponent, FormDirective, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, FormCheckComponent, FormCheckInputDirective, FormCheckLabelDirective, ButtonGroupComponent, ButtonDirective } from '@coreui/angular';
@@ -10,6 +10,8 @@ import { RowComponent, FormDirective, ColComponent, TextColorDirective, CardComp
1010
imports: [RowComponent, ReactiveFormsModule, FormDirective, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, DocsExampleComponent, FormCheckComponent, FormCheckInputDirective, FormCheckLabelDirective, ButtonGroupComponent, ButtonDirective]
1111
})
1212
export class ChecksRadiosComponent {
13+
private formBuilder = inject(UntypedFormBuilder);
14+
1315

1416
inputDisabled: null = null;
1517

@@ -38,11 +40,6 @@ inputDisabled: null = null;
3840
})
3941
});
4042

41-
42-
constructor(
43-
private formBuilder: UntypedFormBuilder
44-
) { }
45-
4643
setCheckBoxValue(controlName: string) {
4744
const btnCheckGroup = this.formGroup.controls['btnCheckGroup'];
4845
const prevValue = btnCheckGroup.get(controlName)?.value;

src/app/views/icons/coreui-icons.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33

44
import { IconDirective, IconSetService } from '@coreui/icons-angular';
@@ -20,12 +20,15 @@ import { DocsLinkComponent } from '@docs-components/public-api';
2020
]
2121
})
2222
export class CoreUIIconsComponent implements OnInit {
23+
private route = inject(ActivatedRoute);
24+
iconSet = inject(IconSetService);
25+
2326
public title = 'CoreUI Icons';
2427
public icons!: [string, string[]][];
2528

26-
constructor(
27-
private route: ActivatedRoute, public iconSet: IconSetService
28-
) {
29+
constructor() {
30+
const iconSet = this.iconSet;
31+
2932
iconSet.icons = { ...freeSet, ...brandSet, ...flagSet };
3033
}
3134

src/app/views/theme/colors.component.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterViewInit, Component, HostBinding, Inject, Input, OnInit, Renderer2, forwardRef, DOCUMENT } from '@angular/core';
1+
import { AfterViewInit, Component, HostBinding, Input, OnInit, Renderer2, forwardRef, DOCUMENT, inject } from '@angular/core';
22
import { NgClass } from '@angular/common';
33

44
import { getStyle, rgbToHex } from '@coreui/utils';
@@ -9,12 +9,9 @@ import { TextColorDirective, CardComponent, CardHeaderComponent, CardBodyCompone
99
imports: [TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, RowComponent, forwardRef(() => ThemeColorComponent)]
1010
})
1111
export class ColorsComponent implements OnInit, AfterViewInit {
12+
private document = inject<Document>(DOCUMENT);
13+
private renderer = inject(Renderer2);
1214

13-
constructor(
14-
@Inject(DOCUMENT) private document: Document,
15-
private renderer: Renderer2
16-
) {
17-
}
1815

1916
public themeColors(): void {
2017
Array.from(this.document.querySelectorAll('.theme-color')).forEach(

src/app/views/widgets/widgets-brand/widgets-brand.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
1+
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, inject } from '@angular/core';
22
import { ChartjsComponent } from '@coreui/angular-chartjs';
33
import { IconDirective } from '@coreui/icons-angular';
44
import { ColComponent, RowComponent, WidgetStatDComponent } from '@coreui/angular';
@@ -21,10 +21,8 @@ type BrandData = {
2121
imports: [RowComponent, ColComponent, WidgetStatDComponent, IconDirective, ChartjsComponent]
2222
})
2323
export class WidgetsBrandComponent implements AfterContentInit {
24+
private changeDetectorRef = inject(ChangeDetectorRef);
2425

25-
constructor(
26-
private changeDetectorRef: ChangeDetectorRef
27-
) {}
2826

2927
@Input() withCharts?: boolean;
3028
// @ts-ignore

src/app/views/widgets/widgets-dropdown/widgets-dropdown.component.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
AfterContentInit,
3-
AfterViewInit,
4-
ChangeDetectionStrategy,
5-
ChangeDetectorRef,
6-
Component,
7-
OnInit,
8-
ViewChild
9-
} from '@angular/core';
1+
import { AfterContentInit, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, ViewChild, inject } from '@angular/core';
102
import { getStyle } from '@coreui/utils';
113
import { ChartjsComponent } from '@coreui/angular-chartjs';
124
import { RouterLink } from '@angular/router';
@@ -21,10 +13,8 @@ import { RowComponent, ColComponent, WidgetStatAComponent, TemplateIdDirective,
2113
imports: [RowComponent, ColComponent, WidgetStatAComponent, TemplateIdDirective, IconDirective, ThemeDirective, DropdownComponent, ButtonDirective, DropdownToggleDirective, DropdownMenuDirective, DropdownItemDirective, RouterLink, DropdownDividerDirective, ChartjsComponent]
2214
})
2315
export class WidgetsDropdownComponent implements OnInit, AfterContentInit {
16+
private changeDetectorRef = inject(ChangeDetectorRef);
2417

25-
constructor(
26-
private changeDetectorRef: ChangeDetectorRef
27-
) {}
2818

2919
data: any[] = [];
3020
options: any[] = [];

src/app/views/widgets/widgets-e/widgets-e.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
1+
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, inject } from '@angular/core';
22
import { getStyle } from '@coreui/utils';
33
import { ChartjsComponent } from '@coreui/angular-chartjs';
44
import { RowComponent, ColComponent, WidgetStatEComponent, TextColorDirective } from '@coreui/angular';
@@ -11,10 +11,10 @@ import { RowComponent, ColComponent, WidgetStatEComponent, TextColorDirective }
1111
imports: [RowComponent, ColComponent, TextColorDirective, WidgetStatEComponent, ChartjsComponent]
1212
})
1313
export class WidgetsEComponent implements AfterContentInit {
14+
private changeDetectorRef = inject(ChangeDetectorRef);
1415

15-
constructor(
16-
private changeDetectorRef: ChangeDetectorRef
17-
) {
16+
17+
constructor() {
1818
this.prepareLabels();
1919
this.prepareDatasets();
2020
this.prepareData();

0 commit comments

Comments
 (0)