Calling a directive after the load of last item in ngFor

戏子无情 提交于 2019-12-06 05:15:25

An approach would be to apply a directive to all rows and pass last. Where last is true the directive actually does something.

@Directive({selector: '[isLast]'})
export class LastDirective{
   @Input() isLast:boolean;
   @Output() lastDone:EventEmitter<boolean> = new EventEmitter<boolean>();
   ngOnInit() {
     if(this.isLast) {
       this.lastDone.emit(true);
     }
   }
}
<tr  *ngFor="let country of countries; let last=last" [isLast]="last" (lastDone)="doSomething()">

You could also create a custom ngFor that provides additional features.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!