我习惯在Angular HTML模板中使用带有"as"的异步管道,以避免复制可观察的订阅,如下所示:
<component *ngIf="(selected$ | async) as selected"></component>
Run Code Online (Sandbox Code Playgroud)
那么我可以在模板中的任何其他地方使用"选中".
但是如果我尝试像这样使用它,在输入中:
<component [param]="(selected$ | async) as selected"></component>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Unexpected token 'as' at column 21 in [categories$ | async as categories]
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?谢谢!
这是正确的,as语法是特定的*ngIf.它不是一个可以在Angular模板中的任何位置使用的通用关键字.
请参阅https://angular.io/api/common/NgIf并搜索NgIfAs课程.
| 归档时间: |
|
| 查看次数: |
705 次 |
| 最近记录: |