2

这是我尝试过的代码。我尝试使用 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>

角js代码:

$scope.select2Options = {
        placeholder : "Select or Add Process/Ingredient",
        formatResult : processList,
        formatSelection : processList,
        escapeMarkup : function (m) {
        return m;
        }

    };
4

1 回答 1

9

在您的选择标签内添加一个空的选项标签,然后将显示占位符。此外,使用 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>
于 2014-09-04T19:56:54.757 回答