I'm looking for a way to set a local template variable who's value is provided by the component.
Component:
@Component({
'my-component
})
@View({
'templateUrl': '/templates/UserAnimals.html'
})
class UserAnimals {
users : Object[];
constructor() {
this.users = [
{ _id: 0, name: 'John' },
{ _id: 1, name: 'Mary' },
];
}
getFavorite(userId : string) : Object {
// return the animal object.
}
}
Template:
<table>
<tr *ngFor="#user of users"
favoriteAnimal="getFavorite(user._id)">
<!-- How do I do this? I'm looking for some way to set favoriteAnimal variable to
value from the component. After which favoriteAnimal is re-usable to all children
of the tr tag. -->
<td>
{{ user.name }}
</td>
<td>
{{ favoriteAnimal.type }}
</td>
<td>
{{ favoriteAnimal.name }}
</td>
</tr>
</table>