在选项中使用 ngIf 和 ngFor [英] Using ngIf and ngFor in option

查看:22
本文介绍了在选项中使用 ngIf 和 ngFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一行中使用 ngIf 和 ngFor.我知道这是不可能的,但有没有其他方法可以做到这一点?

I want to use ngIf and ngFor in one line. I know it is not possible but is there any other method to do this?

这是我的代码:

<option *ngIf="tmpLanguage.id!=languages.id" 
        *ngFor="let tmpLanguage of languages" [ngValue]="tmpLanguage.id">
     {{tmpLanguage.identificatie}}
</option>

推荐答案

一次只能在一个元素上使用一个结构指令.

Only one structural directive is allowed on one element at a time.

作为一种解决方法,您可以使用 <ng-container> 它没有被标记到 DOM

As a workaround you can use <ng-container> which is not stamped to the DOM

<ng-container *ngFor="let tmpLanguage of languages">
  <option *ngIf="tmpLanguage.id!=languages.id"  [ngValue]="tmpLanguage.id" >{{tmpLanguage.identificatie}}</option>
</ng-container>

这篇关于在选项中使用 ngIf 和 ngFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆