Looping over an iterable defined inside of your viewmodel or passed through as a bindable (if a Custom Attribute or Custom Element) can be done like so.
An array of string values
export class MyViewModel {
myIterable = ['String 1', 'String 2', 'String 3', 'String 4'];
}
<template>
<div repeat.for="item of myIterable">${item}</div>
</template>
An array of objects
export class MyViewModel {
myIterable = [
{name: "John Citizen", age: 42},
{name: "Maxwell Smart", age: 75},
{name: "Gary TwoShoes", age: 51}
];
}
<template>
<div repeat.for="item of myIterable">
<strong>Name:</strong> ${item.name}<br>
<strong>Age:</strong> ${item.age}
</div>
</template>
A Map
export class MyViewModel {
myIterable = null;
constructor() {
this.myIterable = new Map();
this.myIterable.set(0, 'My Value');
this.myIterable.set(1, 'Something Different');
this.myIterable.set(2, 'Another String #32837');
}
}
<template>
<div repeat.for="[id, item] of myIterable">
${id}<br>
${item}
</div>
</template>
A numeric loop
<template>
<div repeat.for="i of 10">${i}</div>
</template>