Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

389
Views
Is it possible to have a shorthand local variable in ngFor?

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" ??

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!