简体   繁体   中英

Compound If statement not evaluating to true Angular

I have the following block of code:

<tbody>
    <tr *ngFor="let row of model">
        <ng-container *ngFor="let columnDataName of columnDataNames">
            <td *ngIf="modelConfig[columnDataName] && modelConfig[columnDataName].isVisible">
                <ng-template *ngIf="showRowTextBox && columnDataName === conditionalInputName || columnDataName === conditionCheckBoxName; else otherColumns">
                    <ng-container *ngIf="columnDataName === conditionalInputName">
                        <input type="text" placeholder="Enter text here" [hidden]="!chkEnabled?.checked" (focusout)="onTextBoxFocusOut(row[primaryKeyColumnName], $event)" />
                    </ng-container>
                    <ng-container *ngIf="columnDataName === conditionCheckBoxName">
                        <input type="checkbox" [checked]="chkAll?.checked" #chkEnabled ngModel />
                    </ng-container>
                </ng-template>
                <ng-template #otherColumns>
                    <ng-container *ngIf="modelConfig[columnDataName].isDate;">
                        {{ row[columnDataName] | date:'d MMM yyyy' }}
                    </ng-container>
                    <ng-container *ngIf="modelConfig[columnDataName].isBoolean;">
                        <tfg-toggle onText="Yes" offText="No" [disabled]="true" [value]="row[columnDataName]"></tfg-toggle>
                    </ng-container>
                    <ng-container *ngIf="!modelConfig[columnDataName].isBoolean && !modelConfig[columnDataName].isDate">
                        {{ row[columnDataName] }}
                    </ng-container>
                </ng-template>
            </td>
        </ng-container>
        <td *ngFor="let buttonColumnName of buttonColumnNames">
            <button (click)="executeButtonFunction(row[primaryKeyColumnName], buttonColumnName)" class="btn" [ngClass]="buttonColumnName === 'Delete' ? 'btn-danger' : 'btn-primary'">{{buttonColumnName}}</button>
        </td>
        <!-- <ng-container *ngIf="showRowTextBox">
            <td>
              <input type="text" placeholder="Enter text here" [hidden]="!chkEnabled.checked" (focusout)="onTextBoxFocusOut(row[primaryKeyColumnName], $event)"/>
            </td>
            <td>
              <input type="checkbox" [checked]="chkAll?.checked" #chkEnabled ngModel/>
            </td>
          </ng-container> -->
    </tr>
</tbody>

The page does not render as expected, because the if statement below does not evaluate to true.

<ng-template *ngIf="showRowTextBox && columnDataName === conditionalInputName || columnDataName === conditionCheckBoxName; else otherColumns">

The ShowRowTextBox is set to true, and at some point of the iteration, the columnDataName will either be equal to the conditionalInputName or condtionCheckBoxName .

Is my logic incorrect?

With reference to this article, I changed my markup as follow:

<tbody>
    <tr *ngFor="let row of model">
      <ng-container *ngFor="let columnDataName of columnDataNames">
        <td *ngIf="modelConfig[columnDataName] && modelConfig[columnDataName].isVisible">
          <ng-container *ngIf="showRowTextBox && (columnDataName === conditionalInputName || columnDataName === conditionCheckBoxName); else otherColumns">
            <ng-container *ngIf="columnDataName === conditionalInputName">
              <input type="text" placeholder="Enter text here" [hidden]="!chkEnabled?.checked" (focusout)="onTextBoxFocusOut(row[primaryKeyColumnName], $event)"/>
            </ng-container>
            <ng-container *ngIf="columnDataName === conditionCheckBoxName">
              <input type="checkbox" #chkEnabled ngModel/>
            </ng-container>
          </ng-container>
          <ng-template #otherColumns>
            <ng-container *ngIf="modelConfig[columnDataName].isDate;">
              {{ row[columnDataName] | date:'d MMM yyyy' }}
            </ng-container>
            <ng-container *ngIf="modelConfig[columnDataName].isBoolean;">
              <tfg-toggle onText="Yes" offText="No" [disabled]="true" [value]="row[columnDataName]"></tfg-toggle>
            </ng-container>
            <ng-container *ngIf="!modelConfig[columnDataName].isBoolean && !modelConfig[columnDataName].isDate">
              {{ row[columnDataName] }}
            </ng-container>
          </ng-template>
        </td>
      </ng-container>
      <td *ngFor="let buttonColumnName of buttonColumnNames">
        <button (click)="executeButtonFunction(row[primaryKeyColumnName], buttonColumnName)" class="btn" [ngClass]="buttonColumnName === 'Delete' ? 'btn-danger' : 'btn-primary'">{{buttonColumnName}}</button>
      </td>
      <!-- <ng-container *ngIf="showRowTextBox">
        <td>
          <input type="text" placeholder="Enter text here" [hidden]="!chkEnabled.checked" (focusout)="onTextBoxFocusOut(row[primaryKeyColumnName], $event)"/>
        </td>
        <td>
          <input type="checkbox" [checked]="chkAll?.checked" #chkEnabled ngModel/>
        </td>
      </ng-container> -->
    </tr>
  </tbody>

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