2

I would like to use a component as an item.
Instead of using:

<ul class='biblList'>
    <li *ngFor="let biblCit of biblCits">
        {{ biblCit }}
    </li>
</ul>

I would like to use something like:

<evt-bibliography-item *ngFor="let biblCit of biblCits">
    {{ biblCit }}
</evt-bibliography-item>

Being a novice with angular I don't know how to figure it out.

Memmo
  • 298
  • 3
  • 8
  • 31

4 Answers4

1

here is working example

.ts

biblCits=['1','2','2','3','4','5']

.html

<div *ngFor="let biblCit of biblCits">
    <child-component [parentTimerCount]="biblCit">
    </child-component>
</div>
Chanaka Weerasinghe
  • 5,404
  • 2
  • 26
  • 39
0

You can use iterator *ngFor to iterate through components:

<ng-content *ngFor="let biblCit of biblCits">
  <evt-bibliography-item></evt-bibliography-item>
</ng-content>
StepUp
  • 36,391
  • 15
  • 88
  • 148
0

you can use <ng-content></ng-content> at the component template and this will project the template from the parent

bibliography component template

<div>
<ng-content></ng-content>
</div>

parent

<app-bibliography *ngFor="let biblCit of biblCits">
         {{ biblCit }} 
</app-bibliography>

demo

Muhammed Albarmavi
  • 23,240
  • 8
  • 66
  • 91
0

You can use <ng-content></ng-content> inside of your evt-bibliography-item component's template to access everything passed between your own component tags, in your case the value of {{ biblCit }}

@Component({
  selector: 'evt-bibliography-item',
    template: '<ng-content></ng-content>'
})
export class BibliographyItem {
}
Fussel
  • 1,740
  • 1
  • 8
  • 27