AngularJS: k-ng-model destroys initial index

2 posts, 0 answers
  1. Jakob
    Jakob avatar
    17 posts
    Member since:
    Mar 2013

    Posted 19 May 2015 Link to this post



    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">

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

    Thanks for your help.

  2. Georgi Krustev
    Georgi Krustev avatar
    3725 posts

    Posted 21 May 2015 Link to this post

    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.

    Georgi Krustev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top