本文介绍了Angular 2-ngSwitchCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Angular 2的Switch Case.我试图回显数组,但必须重命名一些单词.这是我以前做过的事情:

I'm learning Switch Case with Angular 2. I'm trying to echo array, but I've have to rename some words. This is what I've before :

<tbody *ngFor="let access of menu.navAccess" class="tr-content">
      <tr class="trParent">
          <td>{{ access.access | uppercase }}</td>
          <td>{{ access.accessType }}</td>
          <td><span class="glyphicon glyphicon-trash actionsBtn" data-toggle="modal" data-target="#deleteModal" (click)="showDelete(access)"></span></td>
      </tr>
</tbody>

现在,我想在access.accessType上包括ngSwitchCase:

<tbody *ngFor="let access of menu.navAccess" class="tr-content">
       <tr class="trParent">
           <td>{{ access.access | uppercase }}</td>
           <td [ngSwitch]="access.accessType">
               <span *ngSwitchCase="BusinessUnit">Business Unit</span>
           </td>
           <td><span class="glyphicon glyphicon-trash actionsBtn" data-toggle="modal" data-target="#deleteModal" (click)="showDelete(access)"></span></td>
       </tr>
 </tbody>

所以,我知道我的access.accessType等于BusinessUnit,但是在我的用户界面中,我想显示Business Unit,但是什么也没显示.

So, I know my access.accessType equals BusinessUnit, but in my UI, I want to show Business Unit, but nothing is showing.

我在做什么错了?

推荐答案

好的,我找到了一个解决方案.因为* ngSwitchCase需要一个表达式,所以我不得不将我的SwitchCase声明为字符串,如下所示:

OK, I've found a solution. Because *ngSwitchCase want an expression, I had to declare my SwitchCase as a string, like this :

<span *ngSwitchCase="'BusinessUnit'">Business Unit</span>

用单引号引起来,而不是:

with single quotes, instead of this :

<span *ngSwitchCase="BusinessUnit">Business Unit</span>

这篇关于Angular 2-ngSwitchCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:46