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

查看:75
本文介绍了在选项中使用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天全站免登陆