angularjs - 占位符在 angularjs select2 中不起作用

标签 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;
        }

    };

最佳答案

在选择标签内添加一个空选项标签,然后将显示占位符。 另外,使用 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>

关于angularjs - 占位符在 angularjs select2 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20663794/

相关文章:

angularjs - angularjs服务中的返回值

javascript - 如何在网格中使用 ng-repeat

javascript - html 中的条件语句

javascript - 更改 ng-model 后 Select2 View 不会更改

javascript - Angular Protractor 测试因 Modal 内的 Select2 失败

javascript - AngularJS 对跨源资源执行 OPTIONS HTTP 请求 => 错误 401

javascript - 为 Node.js 和 Angular 只创建一次模型?

javascript - ng-repeat 指令中的 Angular 选择 : how can I access the children scopes?

angularjs - 如何一起使用 select2 v4.03 和 AngularJS

javascript - 使用未命名链接函数装饰指令