mirror of https://github.com/abpframework/abp.git
Browse Source
Switch DisabledDirective from the OnChanges lifecycle to Angular signal-based reactivity: remove OnChanges/SimpleChanges usage and import effect/input instead. Create an effect that reads the abpDisabled input signal and enables/disables the injected NgControl accordingly, preserving previous behavior while using reactive signals (addresses timing/changes handling referenced in Angular issue).pull/24777/head
1 changed files with 7 additions and 6 deletions
@ -1,18 +1,19 @@ |
|||||
import { Directive, OnChanges, SimpleChanges, inject, input } from '@angular/core'; |
import { Directive, effect, inject, input } from '@angular/core'; |
||||
import { NgControl } from '@angular/forms'; |
import { NgControl } from '@angular/forms'; |
||||
|
|
||||
@Directive({ |
@Directive({ |
||||
selector: '[abpDisabled]', |
selector: '[abpDisabled]', |
||||
}) |
}) |
||||
export class DisabledDirective implements OnChanges { |
export class DisabledDirective { |
||||
private ngControl = inject(NgControl, { host: true }); |
private ngControl = inject(NgControl, { host: true }); |
||||
|
|
||||
readonly abpDisabled = input(false); |
readonly abpDisabled = input(false); |
||||
|
|
||||
// Related issue: https://github.com/angular/angular/issues/35330
|
// Related issue: https://github.com/angular/angular/issues/35330
|
||||
ngOnChanges({ abpDisabled }: SimpleChanges) { |
private disabledEffect = effect(() => { |
||||
if (this.ngControl.control && abpDisabled) { |
const disabled = this.abpDisabled(); |
||||
this.ngControl.control[abpDisabled.currentValue ? 'disable' : 'enable'](); |
if (this.ngControl.control) { |
||||
|
this.ngControl.control[disabled ? 'disable' : 'enable'](); |
||||
} |
} |
||||
} |
}); |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue