jeudi 14 novembre 2019

Angular: *ngFor in parent or child component?

Please look at my app-wall template below. I'm wondering if I should go for <app-brick *ngFor="..."></app-brick>, or <app-bricks> with an *ngFor inside its own template. Is there a best practice when it comes to this, or is it completely case dependent?

@Component({
  selector: 'app-wall',
  template: `
      <app-brick *ngFor="let brick of bricks"></app-brick>

      or

      <app-bricks></app-bricks>
  `
})
@Component({
  selector: 'app-brick',
  template: '<div> I'm a brick! </div>'
})
@Component({
  selector: 'app-bricks',
  template: '<div *ngFor="let brick of bricks"> I'm a brick! </div>'
})

Aucun commentaire:

Enregistrer un commentaire