This is a migrated thread and some comments may be shown as answers.

AngularJS: k-ng-model destroys initial index

1 Answer 95 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Jakob
Top achievements
Rank 1
Jakob asked on 19 May 2015, 11:44 AM

Hi,

 

when i use k-ng-model to bind my value the initially set index does not work. The model variable is not defined on startup. When i change k-ng-model to ng-model the first item is selected.

 Here's my code: 

1.<select class="form-control" kendo-drop-down-list k-options="dropDownOptions" k-ng-delay="dropDownOptions" k-value-primitive="true" k-ng-model="dataRecord">
2.</select>

01.angular.module("KendoDemos", ["kendo.directives"])
02.              .controller("MyCtrl", function ($scope) {
03.                  var dataSource = [];
04.                  dataSource.push({
05.                      value: "1",
06.                      text: "Januar"
07.                  });
08. 
09.                  $scope.dropDownOptions = {
10.                      dataSource: dataSource,
11.                      dataTextField: "text",
12.                      dataValueField: "value",
13.                      index: 0
14.                  };
15.              })

Thanks for your help.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 21 May 2015, 09:32 AM
Hello Jacob,

Even though the value is not defined its value is undefined, which is treated as empty string in the context of the k-ng-model directive. On widget initialization, the directive will set the value of the widget to an empty string ("") (link to the code), which will force the widget to ignore the index option. Unfortunately, we will not be able to change this logic, for instance checking for undefined, because current implementation supports clearing the parent object.

Based on the given explanation, I would suggest you avoid combining index option with ng-model/k-ng-model directives. I believe that you can add an optionLabel to the widget and thus the widget will select it on load.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
DropDownList
Asked by
Jakob
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or