2017-06-29 3 views
0

次のコードでは、行、seatNoが空です。この場合、セクションを表示するだけです。ngForの内部でngIFを使用していくつかの値が空であるかどうかを表示しない方法はありますか?

<p *ngFor="let seat of InfoDetails?.seatInfo"> 
     Section {{seat?.section}} , Row {{seat?.row}},Seat number {{seat?.seatNo}} 
    </p> 

値がない場合、変数のinfrontを両方ともチェックして無効にするにはどうすればよいですか。

出力:(seatNoと行が空の場合)

第23

+0

つの条件が満たされた場合は、レンダリングのテンプレートを使用することができますXテンプレート、そうでない場合はYテンプレート.. https://stackoverflow.com/questions/43006550/how-to-use-ng-else-in-angular-4 – crooksey

+0

あなたが上のサンプルでどのように表示することができます –

+0

あなたのコードを書く必要はありません。 – crooksey

答えて

0
<p *ngFor="let seat of InfoDetails?.seatInfo"> 
     Section {{seat?.section}} , 
    <ng-template [ngIf]="seat?.row"> 
     Row {{seat?.row}}, 
    </ng-template> 
    <ng-template [ngIf]="seat?.seatNo"> 
     Seat number {{seat?.seatNo}} 
    </ng-template> 
    </p> 

詳細は: Structural Directives

関連する問題