The title might seem weird but what im talking about is basically what this link is doing.
Im look for a way to use the current iterated person
in a <tr>
outside of the *ngFor
scope.
In the link he used ng-repeat-start
and ng-repeat-end
to include multiple tag withing the ng-repeat.
How can i achieve the same behavior withing Angular2 using *ngFor
?
You can't use multiple *ngFor s in the same element as those are structural directives and angular handles them in a specific way (basically for each structural directive it creates an ng-template element which then holds the directive itself, you can read more about it here: https://angular.io/guide/structural- ...
The *ngFor directive is used to repeat a portion of HTML template once per each item from an iterable list (Collection). The ngFor is an Angular structural directive and is similar to ngRepeat in AngularJS. Some local variables like Index, First, Last, odd and even are exported by *ngFor directive.
The <ul> tag is not filled by those <li> tag created by *ngFor which makes the "line" of the timeline disappear.
You use the *ngFor directive to traverse over an array object and display the data in the UI.
I had to use the <template>
tag, which made the iterated objected accessible within it.
<ng-template let-person ngFor [ngForOf]="people">
<tr>
<td>{{person.name}}</td>
<td>{{person.gender}}</td>
</tr>
<div>
<span>{{person.details}}</span>
</div>
</ng-template>
Hope it'll help somebody
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With