我有以下模板:
<div>
<span>{{aVariable}}</span>
</div>
Run Code Online (Sandbox Code Playgroud)
并希望最终得到:
<div "let a = aVariable">
<span>{{a}}</span>
</div>
Run Code Online (Sandbox Code Playgroud)
有办法吗?
我正在创建一个自定义* ngIf指令,以在加载时用占位符替换内容。我可以根据需要进行所有工作并在* ngIf指令之后对其进行建模(https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_if.ts)唯一不起作用的是as语法,但看不到任何引用或从何处开始。
*myCustomDirective="loading$ | async as result"
Run Code Online (Sandbox Code Playgroud)
上面的方法不起作用,当loading $ observable发出数据时,结果是不确定的。显示占位符,但是按预期将其替换为内容。(尽管由于不确定的结果,内容还是有错误)
我知道教科书的规则<div *ngFor="let foo of foobars">{{foo.stuff}}</div>变成了<template ngFor let-foo="$implicit" [ngForOf]="foobars"><div>...</div></template>.我的问题是双重的:
即<div *myDirective="item">{{item.stuff}}</div>变成<template myDirective let-item="$implicit"><div>{{item.stuff}}</div></template>?
由于我从上到下阅读了ngFor的源代码,我只能假设这个黑魔法在某个地方的编译器中,我一直在角度github上下,但我不能把手指放在它上面.救命!