首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >*Ngfor组件的替代方案

*Ngfor组件的替代方案
EN

Stack Overflow用户
提问于 2018-04-09 16:41:07
回答 1查看 825关注 0票数 1

在Angular 5中,有没有更好的解决方案?

代码语言:javascript
复制
<div *ngFor="let component of components | async">
    <component-1  *ngIf="component.type === 'some-type-1'"></component-1>
    <component-2  *ngIf="component.type === 'some-type-2'"></component-2>
    <component-3  *ngIf="component.type === 'some-type-3'"></component-3>
</div>
EN

回答 1

Stack Overflow用户

发布于 2018-04-09 17:28:56

作为替代方法,您可以使用自定义管道根据类型过滤组件。显然,您可以自定义您的管道,以更好地适应组件的属性。

代码语言:javascript
复制
<div *ngFor="let component of components | myfilter: 'some-type-1'">
    <component-1></component-1>
</div>

<div *ngFor="let component of components | myfilter: 'some-type-2'">
    <component-2></component-2>
</div>

<div *ngFor="let component of components | myfilter: 'some-type-3'">
    <component-3></component-3>
</div>

Working demo

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49728796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档