首页 > 解决方案 > angular ngFor:如何区分默认值与其他值

问题描述

我正在使用 ngFor 作为下拉 UI 元素。在下拉列表中,第一个条目用于传达信息(例如“请选择国家/地区”),其余是用户需要选择的值。

我希望第一个条目在外观上有点不同,就像变灰一样。

如何才能做到这一点?

标签: htmlcssngfor

解决方案


试试下面:

app.component.html

<div> Months :
   <select (change) = "changemonths($event)" name = "month">
          <option class="default-select" disebled>--select--</option>
      <option *ngFor = "let i of months">{{i}}</option>
   </select>
</div>

app.component.css

.default-select{
background-color:gray;
}

推荐阅读