Angular-Kendo ComboBox placeholder text not working

两盒软妹~` 提交于 2019-11-30 05:15:00

问题


I have a simple angular-kendo ComboBox on a page without an initially selected value. It should show the placeholder text in that case, but instead it's showing ? undefined:undefined ?

HTML

<select kendo-combo-box ng-model="Project" k-options='projectOptions'></select>

JS

app.controller('MyCtrl', function($scope) {    
  $scope.projectData = [
    {name: 'Bob', value: 1},
    {name: 'Tom', value: 2}
  ];

  $scope.projectOptions = {
    placeholder: "'Select...'",
    dataTextField: 'name',
    dataValueField: 'value',
    dataSource: {
      data: $scope.projectData
    }
  }
});

Here's a plunker that shows the problem. Can anyone spot the cause?

This used to work in an older version of angular-kendo, but it's not working in the current version.


回答1:


This is somewhat related to this issue: https://github.com/angular/angular.js/issues/1019

The solution is simple: use an <input> instead of a <select> element:

<input kendo-combo-box ng-model="Project" k-options='projectOptions'/>

app.controller('MyCtrl', function($scope) {
  $scope.projectData = [
    {name: 'Bob', value: 1},
    {name: 'Tom', value: 2}
  ];

  $scope.projectOptions = {
    placeholder: "'Select...'",
    dataTextField: 'name',
    dataValueField: 'value',
    dataSource: {
      data: $scope.projectData
    }
  }
});

(demo)




回答2:


If you are using <Select> instead of <input> you can use simple placeholder="'Project'"

For example:

<select kendo-combo-box="projectComboBox"
        k-data-source="projectDataSourceBox"
        k-data-text-field="'projectName'"
        k-data-value-field="'projectId'"
        k-ng-model="Dialog.ProjectId"
        k-value-primitive="true"                                        
        k-suggest="true"
        required="required"
        k-auto-bind="false"
        k-filter="'contains'"
        k-change="projectChangeBox"
        style="width: 100%"
        placeholder="'Project'">
        </select>


来源:https://stackoverflow.com/questions/23023113/angular-kendo-combobox-placeholder-text-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!