【问题标题】:How can I make var in *ngIf?如何在 *ngIf 中创建 var?
【发布时间】:2022-11-23 15:29:52
【问题描述】:

我有情况:

<test-component *ngIf="(items | somePipe).length"
                [items]="items | somePipe"
></test-component>

我怎样才能从 (items | somePipe) 中制作 var 以便不重复相同的代码

如果有可能这样做的话:

<test-component *ngIf="((items | somePipe) as pipedItems).length"
                [items]="pipedItems"
></test-component>

【问题讨论】:

    标签: javascript angular pipe var angular-ng-if


    【解决方案1】:

    简单地

    <test-component *ngIf="items | somePipe as myItems"
                [items]="myItems"
    ></test-component>
    

    【讨论】:

    • 我需要检查确切的长度
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 2020-03-13
    • 1970-01-01
    相关资源
    最近更新 更多