早上好,我遇到一个占位符无法正常运行的问题。在研究了SO的类似问题之后,得到了一个描述了类似问题的解决方案,但没有针对我的问题的解决方案:
AngularJS: ng-placeholder not working
我有一个选择字段:
<select ng-model="form.experience"
name="experience"
ng-options="e for e in experience"
class="form-control"
data-placeholder="Experience"
tabindex="11"
required=""/>
在控制器中,我有:
$scope.experience = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
然后,在浏览器中,我看到以下内容。我的理解是它应该已经可以工作,但是占位符未显示在选择字段中。希望能得到一些帮助,因为我显然缺少一些东西。
答案 0 :(得分:2)
在使用ng-options时,placeholder无法在select中起作用
两种解决方法:
<select ng-model="form.experience"
name="experience">
<option >Experience</option>
<option ng-repeat="e in experience"></option>
</select>
秒是:
$scope.experience = ['Experience',1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$scope.form.experience = 'Experience';
<select ng-model="form.experience"
name="experience"
ng-options="e for e in experience"
class="form-control"
data-placeholder="Experience"
tabindex="11"
required=""/>