监听ngFor渲染完毕

import { Directive, Input, EventEmitter, Output, AfterViewInit } from '@angular/core';

@Directive({ selector: '[ngForEnd]' })
export class NgForEndDirective implements AfterViewInit {
    @Input() ngForEnd: boolean;
    @Output() ngForEnded: EventEmitterboolean = new EventEmitter();
    constructor() { }
    ngAfterViewInit() {
        if (this.ngForEnd) {
            this.ngForEnded.emit(this.ngForEnd);
        }
    }
}
复制代码
ul
    li *ngFor="let item of list;last as l;" [ngForEnd]="l" (ngForEnded)="ngForEnded($event)"/li
/ul
复制代码
ngForEnded(e: any) {
// 渲染完毕
    console.log(e);
}
复制代码
最新回复(0)
/jishuxrBYkdTpjVDe7lue1ETAEpkRJu2l0WoRzvB86g_3D_3D
8