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
  • 312
  • 2
  • 7
  • 27

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
  • 4,797
  • 2
  • 23
  • 35
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
  • 30,747
  • 12
  • 76
  • 133
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
  • 21,124
  • 5
  • 55
  • 80
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,551
  • 1
  • 9
  • 23