I need to repeat several li
-elements in a list in Angular2 for each item. In angular 1.x I used ng-repeat-start
and ng-repeat-end
for this. I can't find the right way to do it in Angular 2. There are some older blog posts about this, but their suggestions don't work in the newest beta of Angular2.
All <li>
-elements should be repeated for each category:
(which I would normally do with the attribute *ngFor="#category of categories"
- but I can't find where to put it...
Help?
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">
{{ category.title }}
</li>
<li>
<a href="{{ '/music/' + tag.keyword }}" *ngFor="#tag of category.tags" [hidden]="tag.deleted === 1">{{ tag.tag_title_da }}</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Alle musikstykker</li>
<li><a href="/music/all">Alle musikstykker</a></li>
</ul>
In the newer versions it works like this:
--> let-category instead of #category
Thanks for your effort, pixelbits, however the answer was different.
Reading about the asterisk in Template Syntax in the Angular.io guides gives you the clue.
This solved it:
If you want to repeat the contents, use the
template
tag, and remove the*
prefix onngFor
.According to Victor Savkin on
ngFor
andtemplates
:Update angular ^2.0.0
You can use
ng-container
and just change#var
tolet var
.<ng-container>
behaves the same as the<template>
but allows to use the more common syntax.Worked with 5.2.x