简体   繁体   中英

Angular ngModel with an if condition

I'm new in Angular, and I'm trying to write a code that will display a list of checkboxes. If the checkbox is unchecked, it will not be displayed on the list. I'm using ngModel to bring data from an interface. I tried to use *ngIf to only display checked checkboxes, but it did not work. How can I solve this?

The HTML:

<div fxFlex fxLayout="row">
                        <div fxLayout="column" class="pr-40 pl-20">
                            <mat-checkbox class="mt-24 pr-4" disabled name="IsTakenColdEnvironment"
                                [(ngModel)]="rawMaterialInformation.IsTakenColdEnvironment">
                                Açıldığında -18 C Alınmalı
                            </mat-checkbox>
                            <mat-checkbox class="mt-24" disabled name="IsOlfactory"
                                [(ngModel)]="rawMaterialInformation.IsOlfactory">
                                Koku Alan
                            </mat-checkbox>
                            <mat-checkbox class="mt-24" disabled name="IsMetalEffective"
                                [(ngModel)]="rawMaterialInformation.IsMetalEffective">
                                Metal Kontrolü
                            </mat-checkbox>

enter image description here

Add a *ngIf="your_condition" in to your checkbox.

<mat-checkbox class="mt-24" disabled name="IsMetalEffective" *ngIf="rawMaterialInformation.IsMetalEffective"
    [(ngModel)]="rawMaterialInformation.IsMetalEffective">
    Metal Kontrolü
</mat-checkbox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM