From 9e93015572e14105123851074ea43ad5f48ebc08 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Fri, 8 Nov 2024 12:36:54 +0700 Subject: [PATCH] Children do not need to care about parent dependencies --- .../lib/modules/select/abstract-select.component.ts | 5 +++-- .../select/select-enum/select-enum.component.ts | 10 ++-------- .../select-hierarchic/select-hierarchic.component.ts | 8 +------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/projects/natural/src/lib/modules/select/abstract-select.component.ts b/projects/natural/src/lib/modules/select/abstract-select.component.ts index ea401ffa..ccca11f3 100644 --- a/projects/natural/src/lib/modules/select/abstract-select.component.ts +++ b/projects/natural/src/lib/modules/select/abstract-select.component.ts @@ -1,5 +1,5 @@ import {coerceBooleanProperty} from '@angular/cdk/coercion'; -import {Directive, DoCheck, EventEmitter, Input, OnInit, Optional, Output, Self} from '@angular/core'; +import {Directive, DoCheck, EventEmitter, inject, Input, OnInit, Output} from '@angular/core'; import { AbstractControl, ControlValueAccessor, @@ -121,8 +121,9 @@ export abstract class AbstractSelect implements OnInit, ControlValueAccess public onTouched?: () => void; public readonly matcher: ExternalFormControlMatcher; + public readonly ngControl = inject(NgControl, {optional: true, self: true}); - public constructor(@Optional() @Self() public readonly ngControl: NgControl | null) { + public constructor() { if (this.ngControl) { this.ngControl.valueAccessor = this; } diff --git a/projects/natural/src/lib/modules/select/select-enum/select-enum.component.ts b/projects/natural/src/lib/modules/select/select-enum/select-enum.component.ts index 131410aa..16e6c3e0 100644 --- a/projects/natural/src/lib/modules/select/select-enum/select-enum.component.ts +++ b/projects/natural/src/lib/modules/select/select-enum/select-enum.component.ts @@ -1,5 +1,5 @@ -import {Component, Input, OnInit, inject} from '@angular/core'; -import {ControlValueAccessor, FormsModule, NgControl, ReactiveFormsModule} from '@angular/forms'; +import {Component, inject, Input, OnInit} from '@angular/core'; +import {ControlValueAccessor, FormsModule, ReactiveFormsModule} from '@angular/forms'; import {Observable} from 'rxjs'; import {IEnum, NaturalEnumService} from '../../../services/enum.service'; import {AbstractSelect} from '../abstract-select.component'; @@ -42,12 +42,6 @@ export class NaturalSelectEnumComponent extends AbstractSelect implements public items?: Observable; - public constructor() { - const ngControl = inject(NgControl, {optional: true, self: true}); - - super(ngControl); - } - public override ngOnInit(): void { super.ngOnInit(); this.items = this.enumService.get(this.enumName); diff --git a/projects/natural/src/lib/modules/select/select-hierarchic/select-hierarchic.component.ts b/projects/natural/src/lib/modules/select/select-hierarchic/select-hierarchic.component.ts index 01888693..1ee2088c 100644 --- a/projects/natural/src/lib/modules/select/select-hierarchic/select-hierarchic.component.ts +++ b/projects/natural/src/lib/modules/select/select-hierarchic/select-hierarchic.component.ts @@ -1,5 +1,5 @@ import {Component, inject, Input, OnInit} from '@angular/core'; -import {ControlValueAccessor, FormsModule, NgControl, ReactiveFormsModule} from '@angular/forms'; +import {ControlValueAccessor, FormsModule, ReactiveFormsModule} from '@angular/forms'; import {MatDialogConfig} from '@angular/material/dialog'; import {Literal} from '../../../types/types'; import {HierarchicFiltersConfiguration} from '../../hierarchic-selector/classes/hierarchic-filters-configuration'; @@ -96,12 +96,6 @@ export class NaturalSelectHierarchicComponent */ private lockOpenDialog = false; - public constructor() { - const ngControl = inject(NgControl, {optional: true, self: true}); - - super(ngControl); - } - /** * Very important to return something, above all if [select]='displayedValue' attribute value is used */