*ngIf else if in template

后端 未结 8 800
甜味超标
甜味超标 2020-12-07 11:33

How would I have multiple cases in an *ngIf statement? I\'m used to Vue or Angular 1 with having an if, else if, and else

8条回答
  •  盖世英雄少女心
    2020-12-07 11:58

    You can use multiple way based on sitaution:

    1. If you Variable is limited to specific Number or String, best way is using ngSwitch or ngIf:

      
      
      First Number
      Second Number
      Third Number
      Other Number
      First Number Second Number Third Number
      Daniel String
      David String
      Alex String
      Other String
      Alex String David String Daniel String
    2. Above not suitable for if elseif else codes and dynamic codes, you can use below code:

      
      
      
      
      
      
      
          Template for foo between 1 and 3
      
      
      
          Template for foo between 4 and 6
      
      
      
          Template for foo greater than 7
      
      

    Note: You can choose any format, but notice every code has own problems

提交回复
热议问题