Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
Angular 2: devolución de llamada cuando ngFor ha terminado

En Angular 1, he escrito una directiva personalizada ("repetidor listo") para usar con ng-repeat para invocar un método de devolución de llamada cuando se haya completado la iteración:

 if ($scope.$last === true) { $timeout(() => { $scope.$parent.$parent.$eval(someCallbackMethod); }); }

Uso en marcado:

 <li ng-repeat="item in vm.Items track by item.Identifier" repeater-ready="vm.CallThisWhenNgRepeatHasFinished()">

¿Cómo puedo lograr una funcionalidad similar con ngFor en Angular 2?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Puede usar @ViewChildren para ese propósito

 @Component({ selector: 'my-app', template: ` <ul *ngIf="!isHidden"> <li #allTheseThings *ngFor="let i of items; let last = last">{{i}}</li> </ul> <br> <button (click)="items.push('another')">Add Another</button> <button (click)="isHidden = !isHidden">{{isHidden ? 'Show' : 'Hide'}}</button> `, }) export class App { items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; @ViewChildren('allTheseThings') things: QueryList<any>; ngAfterViewInit() { this.things.changes.subscribe(t => { this.ngForRendred(); }) } ngForRendred() { console.log('NgFor is Rendered'); } }

La respuesta original está aquí https://stackoverflow.com/a/37088348/5700401

over 4 years ago · Santiago Trujillo Report

0

Puedes usar algo como esto ( ngFor variables locales ):

 <li *ngFor="#item in Items; #last = last" [ready]="last ? false : true">

Luego puede interceptar cambios de propiedad de entrada con un setter

 @Input() set ready(isReady: boolean) { if (isReady) someCallbackMethod(); }
over 4 years ago · Santiago Trujillo Report

0

Para mí funciona en Angular2 usando Typescript.

 <li *ngFor="let item in Items; let last = last"> ... <span *ngIf="last">{{ngForCallback()}}</span> </li>

Entonces puedes manejar el uso de esta función.

 public ngForCallback() { ... }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!