Angular 2 - ngSwitchCase

淺唱寂寞╮ 提交于 2019-12-23 04:33:33

问题


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>

Now, I want to include ngSwitchCase on access.accessType :

<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>

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

What am I doing wrong ?


回答1:


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>


来源:https://stackoverflow.com/questions/45439023/angular-2-ngswitchcase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!