选择框占位符选项选择默认值为空字符串或未定义或为空

时间:2020-03-02 07:49:36

标签: angular select-options

我要页面渲染时间,在该选择框值empty stringundefinednull中选择占位符

My sample angular code

它只能使用一个值(empty string)。

但是我想要以上三个值(empty stringundefinednull

我的猜测需求解决方案是选项中带有Or-symbol的值。

例如:

<option [value]="''||undefined||null" disabled selected>Select Product</option>

但是它不起作用。如果有人知道该解决方案与我共享

1 个答案:

答案 0 :(得分:1)

[value]无法接受逻辑表达式。只需在模型为''null时将值undefined分配给模型:

this.item.genericByProd = this.item.genericByProd || '';
相关问题