这是我尝试过的代码。我试图添加带有angularjs代码和HTML代码的占位符,但它不适用于这两种情况。请帮助我或建议我在这种情况下如何做
<select ui-select2="select2Options"
style="width:100%"
ng-model="SelectedProcessandIngredients"
data-placeholder="Select or Add Process/Ingredient"
ng-options="c.name group by c.status for c in colors"
ng-change="selectedinnerLoop()" >
</select>
Angular js代码:
$scope.select2Options = {
placeholder : "Select or Add Process/Ingredient",
formatResult : processList,
formatSelection : processList,
escapeMarkup : function (m) {
return m;
}
};
答案 0 :(得分:8)
在select标签内添加一个空选项标签,将显示占位符。 另外,使用ng-repeat代替ng-options。 Select2与ng-options不兼容。
<select ui-select2 ng-model="select2" data-placeholder="Pick a number">
<!-- empty option gets placeholder working -->
<option value=""></option>
<!-- ng-repeat to populate dynamic options -->
<option ng-repeat="number in range" value="{{number.value}}">{{number.text}}</option>
</select>