Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 25eed84

Browse files
committed
fix(template): use constructor injection for templateRef. fixes #1616
Multiple users reported the issue that their IDE cannot infer the typings from our structural directives due to the `inject` method. Using the constructor based injection solves that issue
1 parent 4dca791 commit 25eed84

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

libs/template/experimental/virtual-scrolling/src/lib/virtual-for.directive.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ export class RxVirtualFor<T, U extends NgIterable<T> = NgIterable<T>>
200200
private readonly iterableDiffers = inject(IterableDiffers);
201201
private readonly cdRef = inject(ChangeDetectorRef);
202202
private readonly ngZone = inject(NgZone);
203-
private readonly templateRef = inject(
204-
TemplateRef<RxVirtualForViewContext<T, U>>
205-
);
206203
readonly viewContainer = inject(ViewContainerRef);
207204
private readonly strategyProvider = inject(RxStrategyProvider);
208205
private readonly errorHandler = inject(ErrorHandler);
@@ -595,6 +592,10 @@ export class RxVirtualFor<T, U extends NgIterable<T> = NgIterable<T>>
595592
return true;
596593
}
597594

595+
constructor(
596+
private readonly templateRef: TemplateRef<RxVirtualForViewContext<T, U>>
597+
) {}
598+
598599
/** @internal */
599600
ngOnInit() {
600601
this.values$.pipe(takeUntil(this._destroy$)).subscribe((values) => {

libs/template/for/src/lib/for.directive.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
8989
/** @internal */
9090
private ngZone = inject(NgZone);
9191
/** @internal */
92-
private templateRef =
93-
inject<TemplateRef<RxForViewContext<T, U>>>(TemplateRef);
94-
/** @internal */
9592
private viewContainerRef = inject(ViewContainerRef);
9693
/** @internal */
9794
private strategyProvider = inject(RxStrategyProvider);
@@ -434,6 +431,10 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
434431
/** @internal */
435432
_distinctBy = (a: T, b: T) => a === b;
436433

434+
constructor(
435+
private readonly templateRef: TemplateRef<RxForViewContext<T, U>>
436+
) {}
437+
437438
/** @internal */
438439
ngOnInit() {
439440
this._subscription.add(this.values$.subscribe((v) => (this.values = v)));

libs/template/if/src/lib/if.directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ export class RxIf<T = unknown>
7777
/** @internal */
7878
private ngZone = inject(NgZone);
7979
/** @internal */
80-
private templateRef = inject<TemplateRef<RxIfViewContext<T>>>(TemplateRef);
81-
/** @internal */
8280
private viewContainerRef = inject(ViewContainerRef);
8381

8482
/** @internal */
@@ -489,6 +487,8 @@ export class RxIf<T = unknown>
489487
return this.then ? this.then : this.templateRef;
490488
}
491489

490+
constructor(private readonly templateRef: TemplateRef<RxIfViewContext<T>>) {}
491+
492492
/** @internal */
493493
ngOnInit() {
494494
this.subscription.add(

libs/template/let/src/lib/let.directive.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ export class RxLet<U> implements OnInit, OnDestroy, OnChanges {
103103
/** @internal */
104104
private ngZone = inject(NgZone);
105105
/** @internal */
106-
private nextTemplateRef =
107-
inject<TemplateRef<RxLetViewContext<U>>>(TemplateRef);
108-
/** @internal */
109106
private viewContainerRef = inject(ViewContainerRef);
110107
/** @internal */
111108
private errorHandler = inject(ErrorHandler);
@@ -525,6 +522,8 @@ export class RxLet<U> implements OnInit, OnDestroy, OnChanges {
525522
return true;
526523
}
527524

525+
constructor(private templateRef: TemplateRef<RxLetViewContext<U>>) {}
526+
528527
/** @internal */
529528
ngOnInit() {
530529
this.subscription.add(
@@ -618,7 +617,7 @@ export class RxLet<U> implements OnInit, OnDestroy, OnChanges {
618617

619618
this.templateManager.addTemplateRef(
620619
RxLetTemplateNames.next,
621-
this.nextTemplateRef
620+
this.templateRef
622621
);
623622
this.templateManager.nextStrategy(this.strategyHandler.values$);
624623
}

0 commit comments

Comments
 (0)