首页 文章

Angular multiple ngif else在模板中传递参数

提问于
浏览
0

是否有可能在angular.html中做两个ngIf?

一个例子:

if(1=2){
}else{
    if(){
    }
}

我需要做两次检查 .

检查教师的限制是否为假,以检查教室的可用性 .

下面是我的代码示例 . 我是棱角分明的新手,我不知道一切如何运作 .

<td *ngIf="!restricaoSegUm; else templateName" *ngIf="!restricaoSalaSegUm; else sala" [dragula]='"another-bag"' [dragulaModel]='segUm'>
      <div [@resultadoAnimacao]="animationsState" class="cursor-pointer"  *ngFor='let s1 of segUm' (dblclick)="removeNumbers(s1,this.segUm)">{{s1?.no_diciplinas}}</div>
    </td>

<ng-template #templateName >
    <td style="background-color: rgb(244, 67, 54);"></td>
</ng-template>
<ng-template-sala #sala>
    <td style="background-color: rgb(244, 146, 54);"></td>
</ng-template-sala>

3 回答

  • 0

    你可以将2 * ngIf包装在一起 .

    所以喜欢

    <div ng-if="myVar">
    <div ng-if="myOtherVar">
    <!--
    Your code
    -->
    </div>
    </div>
    
  • 0

    您可以将 conditions 放在一个 *ngFor 中,并且在单个元素上使用2 *ngFor 是不正确的:

    <td *ngIf="!restricaoSegUm && !restricaoSalaSegUm; else templateName" [dragula]='"another-bag"' [dragulaModel]='segUm'>
    
  • 0
    • 你不应该放2 * ngIfs而是改为 *ngIf="conditions; then thenBlock; else elseBlock" .

    • conditions 部分,检查教师限制,一旦在templateName块中,您就可以确定要使用的背景颜色 .

    试试这个:

    <td *ngIf="!restricaoSegUm; else templateName" 
        [dragula]='"another-bag"' [dragulaModel]='segUm'>
        <div [@resultadoAnimacao]="animationsState" class="cursor-pointer"  *ngFor='let s1 of segUm' (dblclick)="removeNumbers(s1,this.segUm)">{{s1?.no_diciplinas}}</div>
    </td>
    
    <ng-template #templateName >
        <td [ngStyle]="restricaoSalaSegUm ? { 'background-color': 'rgb(244, 67, 54)' } : { 'background-color': 'rgb(244, 146, 54);' }">
            <div [@resultadoAnimacao]="animationsState" class="cursor-pointer"  *ngFor='let s1 of segUm' (dblclick)="removeNumbers(s1,this.segUm)">{{s1?.no_diciplinas}}</div>
        </td>
    </ng-template>
    

    我不明白你的逻辑条件是什么评价,希望我指出你正确的方向 .

相关问题