如何使用AngularJS在下拉列表中添加占位符选项

时间:2015-02-02 16:45:12

标签: angularjs

<select>输入中,我们可以添加禁用选项作为占位符:

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="1">January</option>
    ...
</select>

但是我们如何在AngularJS构建的<select>中添加禁用选项,其中ng-options是从控制器提供的?

<select class="month" id="month"
        ng-model="vm.month"
        ng-options="m for m in vm.months">  
</select>

1 个答案:

答案 0 :(得分:5)

我很容易!谢谢HarishR。

<select class="month" id="month"
        ng-model="vm.month"
        ng-options="m for m in vm.months">  
    <option value="" disabled selected>Select your option</option>
</select>

我们甚至可以动态显示/隐藏占位符选项:

<select class="month" id="month"
        ng-model="vm.month"
        ng-options="m for m in vm.months">  
    <option value="" disabled selected ng-hide="vm.month">Select your option</option>
</select>