In Angular 2 ngFor, is it possible to declare a local (short-hand) variable? I mean something like this, but I am not sure about the syntax:
<li *ngFor="let userHasAgenda of agendas | async;
let agenda=userHasAgenda.agenda">
The hypothetical part in question: let agenda=userHasAgenda.agenda
.
Trying something like that, angular gives me:
Parser Error: Unexpected token ., expected identifier, keyword, or string at column 43 in [let uha of agendas | async; let agenda=uha.agenda;]
Edit 1: For comparison, I know this is possible, for example, with index/first/last:
<li *ngFor="let task of tasks | async;
let i = index;
let isFirst = first;
let isLast = last;"
But is it allowed to have custom "aliased variables" ??
No, according to this GitHub issue (Support assigning expression result to local variable within templates), it isn't supported, but there is hope:
14 Dec 2016
Probably something we can consider at a later point according to usage needs.
For now, we have to stick to the five NgFor local variables: index
, first
, last
, even
and odd
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