import { Directive, Input, EventEmitter, Output, AfterViewInit } from '@angular/core';
@Directive({ selector: '[ngForEnd]' })
export class NgForEndDirective implements AfterViewInit {
@Input() ngForEnd: boolean;
@Output() ngForEnded: EventEmitter<boolean> = 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);
}
复制代码