Skip to content

Commit 7b845d3

Browse files
chore: migrate to inject() from constructor dep injection
Angular has moved away from constructors with their dependencies injected in favor of using the inject() function. This migration simply moves us from point A to point B on using inject() for parameters and constructors for initialization above and beyond getting parameters.
1 parent fe68b1a commit 7b845d3

File tree

11 files changed

+55
-57
lines changed

11 files changed

+55
-57
lines changed

src/src/app/common/components/logo/logo.component.ts

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

44
@Component({
@@ -7,14 +7,13 @@ import {Router} from '@angular/router';
77
templateUrl: './logo.component.html',
88
styleUrl: './logo.component.scss'
99
})
10-
export class LogoComponent {
10+
export class LogoComponent {
11+
private router = inject(Router);
12+
1113
@Input() height: number = 50;
1214
@Input() fontSize: number = 35;
1315
@Input() words: string[] = ['inside ;', 'tests ;', 'inside ;', 'quality ;'];
1416

15-
constructor(private router: Router) {
16-
}
17-
1817
sendToIndex() {
1918
this.router.navigate(['/']);
2019
}

src/src/app/service/nullinside-null.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Injectable} from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import {Observable} from 'rxjs';
33
import {environment} from '../../environments/environment';
44
import {HttpClient} from '@angular/common/http';
@@ -7,9 +7,9 @@ import {ImdbSearch} from '../common/interface/imdb-search';
77
@Injectable({
88
providedIn: 'root'
99
})
10-
export class NullinsideNullService {
11-
constructor(private httpClient: HttpClient) {
12-
}
10+
export class NullinsideNullService {
11+
private httpClient = inject(HttpClient);
12+
1313

1414
getImdbSearchQuick(search: string): Observable<ImdbSearch> {
1515
return this.httpClient.get<ImdbSearch>(`${environment.nullApiUrl}/imdb/search/quick?search=${search}`);

src/src/app/service/nullinside-twitch-bot.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Injectable} from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import {HttpClient} from "@angular/common/http";
33
import {Observable} from "rxjs";
44
import {environment} from "../../environments/environment";
@@ -8,9 +8,9 @@ import {TwitchBotConfig} from "../common/interface/twitch-bot-config";
88
@Injectable({
99
providedIn: 'root'
1010
})
11-
export class NullinsideTwitchBotService {
12-
constructor(private httpClient: HttpClient) {
13-
}
11+
export class NullinsideTwitchBotService {
12+
private httpClient = inject(HttpClient);
13+
1414

1515
getIsMod(): Observable<TwitchBotIsModResponse> {
1616
return this.httpClient.get<TwitchBotIsModResponse>(`${environment.twitchBotApiUrl}/bot/mod`);

src/src/app/service/nullinside.service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Injectable} from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import {HttpClient} from "@angular/common/http";
33
import {Observable} from "rxjs";
44
import {environment} from "../../environments/environment";
@@ -9,10 +9,9 @@ import {FeatureToggleResponse} from "../common/interface/feature-toggle-response
99
@Injectable({
1010
providedIn: 'root'
1111
})
12-
export class NullinsideService {
12+
export class NullinsideService {
13+
private httpClient = inject(HttpClient);
1314

14-
constructor(private httpClient: HttpClient) {
15-
}
1615

1716
validateToken(token: string): Observable<boolean> {
1817
return this.httpClient.post<boolean>(`${environment.apiUrl}/user/token/validate`, {token: token});

src/src/app/view/home/home.component.ts

Lines changed: 5 additions & 6 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 {NullinsideService} from "../../service/nullinside.service";
33
import {VM_ADMIN} from "../../common/constants";
44
import {WebsiteApp} from "../../common/interface/website-app";
@@ -17,7 +17,10 @@ import {UserRolesResponse} from "../../common/interface/user-roles-response";
1717
templateUrl: './home.component.html',
1818
styleUrl: './home.component.scss'
1919
})
20-
export class HomeComponent implements OnInit {
20+
export class HomeComponent implements OnInit {
21+
private api = inject(NullinsideService);
22+
private router = inject(Router);
23+
2124
public roles: string[] | null = null;
2225
public error: string | null = null;
2326
public userIsLoggedIn: boolean = false;
@@ -38,10 +41,6 @@ export class HomeComponent implements OnInit {
3841
}
3942
];
4043

41-
constructor(private api: NullinsideService,
42-
private router: Router) {
43-
}
44-
4544
ngOnInit(): void {
4645
this.userIsLoggedIn = null !== localStorage.getItem('auth-token');
4746

src/src/app/view/imdb-search/imdb-search.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnDestroy} from '@angular/core';
1+
import { Component, OnDestroy, inject } from '@angular/core';
22
import {LogoComponent} from '../../common/components/logo/logo.component';
33
import {NullinsideNullService} from '../../service/nullinside-null.service';
44
import {MatFormFieldModule} from '@angular/material/form-field';
@@ -20,16 +20,14 @@ import {ImdbSearchItems} from '../../common/interface/imdb-search';
2020
templateUrl: './imdb-search.component.html',
2121
styleUrl: './imdb-search.component.scss'
2222
})
23-
export class ImdbSearchComponent implements OnDestroy {
23+
export class ImdbSearchComponent implements OnDestroy {
24+
private api = inject(NullinsideNullService);
25+
2426
searching: boolean = false;
2527
quickSubscription: Subscription | null = null;
2628
longSubscription: Subscription | null = null;
2729
public rows: ImdbSearchItems[] = [];
2830

29-
constructor(private api: NullinsideNullService) {
30-
31-
}
32-
3331
ngOnDestroy(): void {
3432
if (this.quickSubscription) {
3533
this.quickSubscription.unsubscribe();

src/src/app/view/login-landing-desktop/login-landing-desktop.component.ts

Lines changed: 5 additions & 5 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 {NullinsideService} from "../../service/nullinside.service";
33
import {ActivatedRoute, ParamMap} from "@angular/router";
44
import {Errors} from "../login-landing/errors";
@@ -20,14 +20,14 @@ import {CdkCopyToClipboard} from "@angular/cdk/clipboard";
2020
templateUrl: './login-landing-desktop.component.html',
2121
styleUrl: './login-landing-desktop.component.scss'
2222
})
23-
export class LoginLandingDesktopComponent implements OnInit {
23+
export class LoginLandingDesktopComponent implements OnInit {
24+
private api = inject(NullinsideService);
25+
private route = inject(ActivatedRoute);
26+
2427
error: string = '';
2528
oAuth: OAuth | null = null;
2629
loading: boolean = true;
2730

28-
constructor(private api: NullinsideService, private route: ActivatedRoute) {
29-
}
30-
3131
ngOnInit(): void {
3232
this.route.queryParamMap.subscribe({
3333
next: (params: ParamMap) => {

src/src/app/view/login-landing/login-landing.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnDestroy, OnInit} from '@angular/core';
1+
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
22
import {NullinsideService} from "../../service/nullinside.service";
33
import {LogoComponent} from "../../common/components/logo/logo.component";
44
import {LoadingIconComponent} from "../../common/components/loading-icon/loading-icon.component";
@@ -16,13 +16,14 @@ import {Errors} from "./errors";
1616
templateUrl: './login-landing.component.html',
1717
styleUrl: './login-landing.component.scss'
1818
})
19-
export class LoginLandingComponent implements OnInit, OnDestroy {
19+
export class LoginLandingComponent implements OnInit, OnDestroy {
20+
private api = inject(NullinsideService);
21+
private route = inject(ActivatedRoute);
22+
private router = inject(Router);
23+
2024
timerId: number = -1;
2125
error: string = '';
2226

23-
constructor(private api: NullinsideService, private route: ActivatedRoute, private router: Router) {
24-
}
25-
2627
ngOnDestroy(): void {
2728
if (this.timerId !== -1) {
2829
clearTimeout(this.timerId);

src/src/app/view/login/login.component.ts

Lines changed: 7 additions & 3 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 {LogoComponent} from "../../common/components/logo/logo.component";
33
import {environment} from "../../../environments/environment";
44
import {NullinsideService} from "../../service/nullinside.service";
@@ -17,15 +17,19 @@ import {TwitchLoginComponent} from '../../common/components/twitch-login/twitch-
1717
templateUrl: './login.component.html',
1818
styleUrl: './login.component.scss'
1919
})
20-
export class LoginComponent implements OnInit {
20+
export class LoginComponent implements OnInit {
21+
private api = inject(NullinsideService);
22+
private router = inject(Router);
23+
private route = inject(ActivatedRoute);
24+
2125
loginUrl: string;
2226
checkingLogin = false;
2327
showGmail = true;
2428
pageDestinations = [
2529
'/home'
2630
];
2731

28-
constructor(private api: NullinsideService, private router: Router, private route: ActivatedRoute) {
32+
constructor() {
2933
this.loginUrl = `${environment.apiUrl}/user/login`;
3034
}
3135

src/src/app/view/twitch/twitch-bot-config/twitch-bot-config.component.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnDestroy, OnInit} from '@angular/core';
1+
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
22
import {LogoComponent} from '../../../common/components/logo/logo.component';
33
import {MatButton} from '@angular/material/button';
44
import {NullinsideTwitchBotService} from "../../../service/nullinside-twitch-bot.service";
@@ -29,7 +29,14 @@ import {Location} from "@angular/common";
2929
templateUrl: './twitch-bot-config.component.html',
3030
styleUrl: './twitch-bot-config.component.scss'
3131
})
32-
export class TwitchBotConfigComponent implements OnInit, OnDestroy {
32+
export class TwitchBotConfigComponent implements OnInit, OnDestroy {
33+
private twitchBotApi = inject(NullinsideTwitchBotService);
34+
private api = inject(NullinsideService);
35+
private snackBar = inject(MatSnackBar);
36+
private location = inject(Location);
37+
private router = inject(Router);
38+
private route = inject(ActivatedRoute);
39+
3340
public botIsMod: boolean | null = null;
3441
public timerId: number = -1;
3542
public error: string = '';
@@ -38,14 +45,6 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy {
3845
public banKnownBots = true;
3946
public waitingForSave = false;
4047

41-
constructor(private twitchBotApi: NullinsideTwitchBotService,
42-
private api: NullinsideService,
43-
private snackBar: MatSnackBar,
44-
private location: Location,
45-
private router: Router,
46-
private route: ActivatedRoute) {
47-
}
48-
4948
ngOnDestroy(): void {
5049
if (this.timerId !== -1) {
5150
clearTimeout(this.timerId);

0 commit comments

Comments
 (0)