From 780cf42ff4ca7a840243e63fba51e40db62413cd Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Mon, 25 Mar 2024 15:42:14 +0300 Subject: [PATCH] update: replacing the constructor service declarations with injection --- .../apps/dev-app/src/app/home/home.component.ts | 5 +++-- .../src/lib/components/login/login.component.ts | 16 +++++++--------- .../application-layout.component.ts | 8 +++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/npm/ng-packs/apps/dev-app/src/app/home/home.component.ts b/npm/ng-packs/apps/dev-app/src/app/home/home.component.ts index 28a70067ef..b6a6082a6c 100644 --- a/npm/ng-packs/apps/dev-app/src/app/home/home.component.ts +++ b/npm/ng-packs/apps/dev-app/src/app/home/home.component.ts @@ -1,17 +1,18 @@ import { AuthService } from '@abp/ng.core'; -import { Component } from '@angular/core'; +import { Component, inject } from '@angular/core'; @Component({ selector: 'app-home', templateUrl: './home.component.html', }) export class HomeComponent { + private authService = inject(AuthService); + loading = false; get hasLoggedIn(): boolean { return this.authService.isAuthenticated; } - constructor(private authService: AuthService) {} login() { this.loading = true; this.authService.navigateToLogin(); diff --git a/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts b/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts index 4ea5401092..81636eef03 100644 --- a/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts +++ b/npm/ng-packs/packages/account/src/lib/components/login/login.component.ts @@ -1,6 +1,6 @@ import { AuthService, ConfigStateService } from '@abp/ng.core'; import { ToasterService } from '@abp/ng.theme.shared'; -import { Component, Injector, OnInit } from '@angular/core'; +import { Component, Injector, OnInit, inject } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { throwError } from 'rxjs'; import { catchError, finalize } from 'rxjs/operators'; @@ -14,6 +14,12 @@ const { maxLength, required } = Validators; templateUrl: './login.component.html', }) export class LoginComponent implements OnInit { + protected injector = inject(Injector); + protected fb = inject(UntypedFormBuilder); + protected toasterService = inject(ToasterService); + protected authService = inject(AuthService); + protected configState = inject(ConfigStateService); + form!: UntypedFormGroup; inProgress?: boolean; @@ -22,14 +28,6 @@ export class LoginComponent implements OnInit { authWrapperKey = eAccountComponents.AuthWrapper; - constructor( - protected injector: Injector, - protected fb: UntypedFormBuilder, - protected toasterService: ToasterService, - protected authService: AuthService, - protected configState: ConfigStateService, - ) {} - ngOnInit() { this.init(); this.buildForm(); diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts index 32dd47bad6..ba1e2cfa9c 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts @@ -1,9 +1,8 @@ -import {eLayoutType, SubscriptionService} from '@abp/ng.core'; +import { eLayoutType, SubscriptionService } from '@abp/ng.core'; import { collapseWithMargin, slideFromBottom } from '@abp/ng.theme.shared'; -import {AfterViewInit, Component} from '@angular/core'; +import { AfterViewInit, Component, inject } from '@angular/core'; import { LayoutService } from '../../services/layout.service'; - @Component({ selector: 'abp-layout-application', templateUrl: './application-layout.component.html', @@ -11,11 +10,10 @@ import { LayoutService } from '../../services/layout.service'; providers: [LayoutService, SubscriptionService], }) export class ApplicationLayoutComponent implements AfterViewInit { + public service = inject(LayoutService); // required for dynamic component static type = eLayoutType.application; - constructor(public service: LayoutService) {} - ngAfterViewInit() { this.service.subscribeWindowSize(); }