Angular ui-select 占位符不起作用

Wil*_*ook 5 javascript select angularjs angularjs-select2 ui-select

我们一直在使用 ui-select ( https://github.com/angular-ui/ui-select ) 来主题下拉菜单,如 select2。此功能主要从一个方面发挥作用:默认占位符。

该代码主要遵循 ui-select 演示(此页面上的第三个示例:http : //plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview)。

就我而言,默认文本应该是“占位符”属性的文本。相反,它显示为空白,直到您选择一个选项。我们一直在使用一个技巧,我们在 Angular 控制器中设置 ui-select-match 的值来解决这个问题,但这远非完美,显然不是应该如何使用它。

<ui-select data-ng-model="producttype.selected" theme="select2" name="product-type">
    <ui-select-match placeholder="Select a product type">
        {{$select.selected.title}}
    </ui-select-match>
    <ui-select-choices repeat="producttype in productTypeOptions | filter: $select.search">
        <span ng-bind-html="producttype.title | highlight: $select.search"></span>
    </ui-select-choices>                                               
</ui-select>
Run Code Online (Sandbox Code Playgroud)

有没有人以前遇到过这个问题,或者对我们做错了什么有任何想法?

tim*_*tom 3

如果您禁用搜索,即使没有选择,这也会隐藏占位符。

占位符 span 元素:

<span ng-show="$select.searchEnabled && $select.isEmpty()" class="select2-chosen ng-binding ng-hide">My Placeholder</span>
Run Code Online (Sandbox Code Playgroud)

只需删除模板 .js 文件中的“$select.searchEnabled &&”,占位符就会再次出现。

正如github 上的 hthabet所见