[英]Angular async pipe with as and let
I have a store state that I'm getting using an observable and the async
pipe. 我有一个正在使用可观察和async
管道的存储状态。 I'm using the as
syntax to read the returned object. 我正在使用as
语法读取返回的对象。
This object is complex, and has fields that are referenced by another async
observable to display information. 该对象很复杂,并且具有可观察到的另一个async
引用的字段以显示信息。
Could I do something like the following? 我可以做以下事情吗?
<div *ngIf="(fileObs$ | async) as files; let fileList= files[user.UserId]">
<div *ngFor="let file of fileList">
...
</div>
<!-- instead of -->
<div *ngFor="let file of files[user.UserId]">
...
</div>
You can use ng-template
to declare new variable fileList
and use ng-container
to wait for asynchronous data to load which then activates the template
您可以使用ng-template
声明新的变量fileList
并使用ng-container
等待加载异步数据,然后激活template
<ng-container *ngTemplateOutlet="files; context:{file :fileObs$ | async}"></ng-container>
<ng-template #files let-fileList="file[user.UserId]">
File List
<br>-------
<div *ngFor="let file of fileList ">
{{file}}
</div>
</ng-template>
I am not filtering user.UserId
in my demo, but you can definitely do that while assigning data to fileList
as let-fileList="file[user.UserId]"
我没有在演示中过滤user.UserId
,但是您可以在将数据分配给fileList
作为let-fileList="file[user.UserId]"
做到这一点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.