Dan Cancro Dan Cancro - 6 months ago 45
AngularJS Question

In <template ngFor #item [ngForOf]="items">, item displays as [object Object]

If I interpolate a string variable in a repeated

<li>
it shows up correctly, but if I put it in a
<template><li>
it shows up as [object Object]. Why is that? I've seen a few evolutions of the
<template>
syntax but none seems to work.

plunk

Answer

If you use #item then item will refer to TemplateRef. You need to use let-item like this:

<template ngFor let-item [ngForOf]="items">
  <li>{{item}}</li>
</template>