我有以下代码块:
<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>
该页面无法呈现预期的效果,因为下面的if
语句的求值结果为true。
<ng-template *ngIf="showRowTextBox && columnDataName === conditionalInputName || columnDataName === conditionCheckBoxName; else otherColumns">
ShowRowTextBox
设置为true,并且在迭代的某个时刻,columnDataName
将等于conditionalInputName
或condtionCheckBoxName
。
我的逻辑不正确吗?
答案 0 :(得分:0)
参考this文章,我将标记更改如下:
<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>