在 ngFor 中可以有一个 shorthand 局部变量吗?

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

在Angular 2 ngFor 中,是否可以声明局部(速记)变量?我的意思是这样的,但我不确定语法:

<li *ngFor="let userHasAgenda of agendas | async;
    let agenda=userHasAgenda.agenda">

所讨论的假设部分:let agenda=userHasAgenda.agenda。 尝试这样的事情,angular 给了我: Parser Error: Unexpected token ., expected identifier, keyword, or string at column 43 in [let uha of agendas | async; let agenda=uha.agenda;]

编辑 1: 为了比较,我知道这是可能的,例如 index/first/last:

<li *ngFor="let task of tasks | async;
    let i = index;
    let isFirst = first;
    let isLast = last;"

但是是否允许自定义 "aliased variables" ??

不,根据这个GitHub问题(Support assigning expression result to local variable within templates),不支持,但有希望:

14 Dec 2016

Probably something we can consider at a later point according to usage needs.

目前,我们必须坚持 five NgFor local variablesindexfirstlastevenodd