diff --git a/projects/cdk/utils/miscellaneous/directive-binding.ts b/projects/cdk/utils/miscellaneous/directive-binding.ts index 2cf47a2699b5..2afa43fe6ae0 100644 --- a/projects/cdk/utils/miscellaneous/directive-binding.ts +++ b/projects/cdk/utils/miscellaneous/directive-binding.ts @@ -1,13 +1,13 @@ -import type {ProviderToken, WritableSignal} from '@angular/core'; +import type {ProviderToken, Signal, WritableSignal} from '@angular/core'; import {effect, inject, isSignal, signal} from '@angular/core'; export function tuiDirectiveBinding( token: ProviderToken, key: G, - initial: T[G] extends WritableSignal ? R : T[G], + initial: T[G] extends WritableSignal ? R | Signal : Signal | T[G], ): WritableSignal { - const result = signal(initial); - const directive = inject(token); + const result: any = isSignal(initial) ? initial : signal(initial); + const directive = inject(token, {self: true}); effect( () => { diff --git a/projects/cdk/utils/miscellaneous/directive-listener.ts b/projects/cdk/utils/miscellaneous/directive-listener.ts index 128f450db349..2d1d4d7624a3 100644 --- a/projects/cdk/utils/miscellaneous/directive-listener.ts +++ b/projects/cdk/utils/miscellaneous/directive-listener.ts @@ -14,7 +14,7 @@ export function tuiDirectiveListener>( token: ProviderToken, key: K, ): Signal> { - const prop: any = inject(token)[key]; + const prop: any = inject(token, {self: true})[key]; return isSignal(prop) ? prop : toSignal(prop); }