在ngSwitchCase中使用额外的参数 [英] Using extra parameter in ngSwitchCase

查看:104
本文介绍了在ngSwitchCase中使用额外的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想强调一下,我已经看过很多页面,例如两个有角度的开关案例值,但它们不能解决我的问题.

First of all, want to emphasize that I had already have a look at many pages e.g. Two switch case values in angular but they cannot fix my problem.

我在Angular项目的html页面中采用以下方法,并且根据i参数进行切换没有任何问题.另一方面,在组件端有一个名为loading的参数,我还需要在ngSwitchCase中使用此值.但是以下代码不起作用,并且忽略了loading参数的值.那么,我该如何使用呢?

I have the following approach in the html page of my Angular project and I switch according to i parameter without any problem. On the other hand, there is a parameter called loading on component side and I also need to use this value in ngSwitchCase. But the following code does not work and ignore loading parameter's value. So, how can I use it?

<ng-container [ngSwitch]="i">
    <ng-container *ngSwitchCase="i === 0 && loading === true">
        <!-- other stuff -->
    </ng-container>
</ng-container>

推荐答案

使用loading条件在其中创建另一个ng-container.

Create another ng-container inside with the loading condition.

<ng-container [ngSwitch]="i">
    <ng-container *ngSwitchCase="0">
        <ng-container *ngIf="loading">
            // do stuff
        </ng-container>
    </ng-container>
</ng-container>

这篇关于在ngSwitchCase中使用额外的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆