angular 中*ngIf 和*ngSwitch判断语句

<div style="text-align:center">
  <h1>
    Welcome to {{ title }}!
  </h1>
  <p *ngIf="true">show</p>
  <p *ngIf="isShow">hide</p>
  <p template="ngIf true">这是 ngIF 判断是否显示</p>

  <ul [ngSwitch]="status">
    <li *ngSwitchCase="1">已支付</li>
    <li *ngSwitchCase="2">订单已经确认</li> 
    <li *ngSwitchCase="3">已发货</li>
    <li *ngSwitchDefault>无效</li>
    </ul>
</div>
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'angulardemo';
  status='2';
  isShow=false;
}

效果:

猜你喜欢

转载自www.cnblogs.com/loaderman/p/10894423.html