占位符不在angularjs select2中工作

时间:2013-12-18 16:48:21

标签: angularjs angularjs-select2

这是我尝试过的代码。我试图添加带有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;
        }

    };

1 个答案:

答案 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>