I am trying to create a component that will do some stuff and loop over a result set. I want to be able to provide a "template" for the items in the looped result set.
For instance, this is kind of the idea I am going for:
<search-field> <ng-template let-item> <span><strong>{{item.foo}}</strong></span> <span>{{item.bar}}</span> </ng-template> </search-field> The content within the search-field component should be used as a template for each iteration of the looped result set within that component.
This is how the search-field component may look:
<div class="search-container"> <div class="search-input"> <input type="text" class="form-control" placeholder="Search users..." [(ngModel)]="searchString" (ngModelChange)="searchStringChanged($event)"> <div class="md-icon">search</div> </div> <ul class="search-results" *ngIf="searchResults.length > 0"> <li class="search-results__item" *ngFor="let result of searchResults"> <ng-content [item]="item"></ng-content> <!-- Template should be used here on each iteration and allow to pass in "item" to use in example up above --> </li> </ul> </div> How can I pass each item of the loop to the ng-content so that I have access to it in the code of the first example?