Skip to content

Commit 9fdb0d2

Browse files
authored
fix: use inject in ListViewComponent (#102)
1 parent abdf398 commit 9fdb0d2

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

packages/angular/src/lib/cdk/list-view/list-view.component.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, Directive, DoCheck, ElementRef, EmbeddedViewRef, EventEmitter, forwardRef, Host, HostListener, Inject, InjectionToken, Input, IterableDiffer, IterableDiffers, OnDestroy, Output, TemplateRef, ViewChild, ViewContainerRef, ɵisListLikeIterable as isListLikeIterable } from '@angular/core';
1+
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, Directive, DoCheck, ElementRef, EmbeddedViewRef, EventEmitter, forwardRef, Host, HostListener, inject, Inject, InjectionToken, Input, IterableDiffer, IterableDiffers, NgZone, OnDestroy, Output, TemplateRef, ViewChild, ViewContainerRef, ɵisListLikeIterable as isListLikeIterable } from '@angular/core';
22
import { ItemEventData, KeyedTemplate, LayoutBase, ListView, ObservableArray, profile, View } from '@nativescript/core';
33

44
import { extractSingleViewRecursive } from '../../element-registry/registry';
@@ -96,7 +96,12 @@ export class ListViewComponent<T = any> implements DoCheck, OnDestroy, AfterCont
9696
return this.templatedItemsView;
9797
}
9898

99-
protected templatedItemsView: ListView;
99+
private readonly _iterableDiffers: IterableDiffers = inject(IterableDiffers);
100+
private readonly _changeDetectorRef: ChangeDetectorRef = inject(ChangeDetectorRef);
101+
private readonly _elementRef: ElementRef = inject(ElementRef);
102+
103+
// I believe this only exists so this can be inherited and people can override it.
104+
protected templatedItemsView: ListView = this._elementRef.nativeElement;
100105
protected _items: T[] | ObservableArray<T>;
101106
protected _differ: IterableDiffer<T>;
102107
protected _templateMap: Map<string, NsTemplatedItem<T>>;
@@ -130,8 +135,24 @@ export class ListViewComponent<T = any> implements DoCheck, OnDestroy, AfterCont
130135
this.templatedItemsView.items = this._items;
131136
}
132137

133-
constructor(_elementRef: ElementRef, private readonly _iterableDiffers: IterableDiffers, private readonly _changeDetectorRef: ChangeDetectorRef) {
134-
this.templatedItemsView = _elementRef.nativeElement;
138+
/**
139+
* @deprecated
140+
*/
141+
constructor(_elementRef: ElementRef);
142+
/**
143+
* @deprecated
144+
*/
145+
constructor(_elementRef: ElementRef, _iterableDiffers: IterableDiffers, _changeDetectorRef: ChangeDetectorRef);
146+
/**
147+
* @deprecated
148+
*/
149+
constructor(_elementRef: ElementRef, _iterableDiffers: IterableDiffers, _ngZone: NgZone);
150+
constructor();
151+
// this elementRef is only here for backwards compatibility reasons
152+
constructor(_elementRef?: ElementRef) {
153+
if (_elementRef) {
154+
this.templatedItemsView = _elementRef.nativeElement;
155+
}
135156
}
136157

137158
ngAfterContentInit() {

0 commit comments

Comments
 (0)