Skip to content

Commit

Permalink
Children do not need to care about parent dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Nov 8, 2024
1 parent 5fd028b commit 9e93015
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -121,8 +121,9 @@ export abstract class AbstractSelect<V, I> implements OnInit, ControlValueAccess
public onTouched?: () => void;

public readonly matcher: ExternalFormControlMatcher<V, I>;
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,12 +42,6 @@ export class NaturalSelectEnumComponent extends AbstractSelect<V, V> implements

public items?: Observable<IEnum[]>;

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 9e93015

Please sign in to comment.