mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 21:15:24 +08:00
refactor(angular): enable TS strict
This commit is contained in:
@ -41,18 +41,18 @@ export class VirtualScroll {
|
||||
]);
|
||||
}
|
||||
|
||||
private nodeRender(el: HTMLElement|null, cell: any, index?: number) {
|
||||
private nodeRender(el: HTMLElement|null, cell: any, index: number) {
|
||||
if (!el) {
|
||||
const node = this.itmTmp.viewContainer.createEmbeddedView(
|
||||
this.getComponent(cell.type),
|
||||
new VirtualContext(null, null, null),
|
||||
{ $implicit: null, index },
|
||||
index
|
||||
);
|
||||
el = getElement(node);
|
||||
(el as any)['$ionView'] = node;
|
||||
}
|
||||
const node = (el as any)['$ionView'];
|
||||
const ctx = node.context;
|
||||
const ctx = node.context as VirtualContext;
|
||||
ctx.$implicit = cell.value;
|
||||
ctx.index = cell.index;
|
||||
node.detectChanges();
|
||||
@ -65,11 +65,11 @@ export class VirtualScroll {
|
||||
case 1: return this.hdrTmp.templateRef;
|
||||
case 2: return this.ftrTmp.templateRef;
|
||||
}
|
||||
return null;
|
||||
throw new Error('template for virtual item was not provided');
|
||||
}
|
||||
}
|
||||
|
||||
function getElement(view: EmbeddedViewRef<VirtualContext>): HTMLElement {
|
||||
function getElement(view: EmbeddedViewRef<VirtualContext>): HTMLElement | null {
|
||||
const rootNodes = view.rootNodes;
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
if (rootNodes[i].nodeType === 1) {
|
||||
|
@ -1,14 +1,5 @@
|
||||
|
||||
export class VirtualContext {
|
||||
|
||||
constructor(public $implicit: any, public index: number, public count: number) { }
|
||||
|
||||
get first(): boolean { return this.index === 0; }
|
||||
|
||||
get last(): boolean { return this.index === this.count - 1; }
|
||||
|
||||
get even(): boolean { return this.index % 2 === 0; }
|
||||
|
||||
get odd(): boolean { return !this.even; }
|
||||
|
||||
export interface VirtualContext {
|
||||
$implicit: any;
|
||||
index: number;
|
||||
}
|
||||
|
Reference in New Issue
Block a user