Apply kendo dropdownlist style only on angular select

耗尽温柔 提交于 2019-12-10 19:17:16

问题


I have a select which is being populated using angular binding.

<select class='clsBucket' id='optBuckets' ng-options='opt as opt.name for opt in buckets' ng-model='bucketSelected' ng-change='changeBucket()'>

Now i want to apply the Kendo dropdownlist style on this select , but i don't want to populate the options using kendo datasource etc and continue to do that using angular.

If i use $('#optBuckets').kendoDropDownList() then i get the requiired style applied but the binding data is lost.

Any help in order to resolve that is highly appreciated.


回答1:


The above code lists "buckets" as the data source. With that in mind, the promise which assigns 'buckets' to the scope should have it's promise exposed on the scope. From there a directive can access it (here called 'bucketsPromise')

The code in the controller may look like such:

$scope.bucketsPromise = bucketsService.get().then(function(data) {
  $scope.buckets = data;
}).promise;

The directive will the appear as such:

.directive('angularToKendoDropdown', function() {
  return {
    scope: {
      'bindToCtrl': '&dataSourcePromise'
    },
    link: function(scope, element, attr) {
        scope.bindToCtrl.then(function() {
          $(element).kendoDropDownList();
        })
    }
 };
});

The given select would appear as such:

<select class='clsBucket angular-to-kendo-dropdown' id='optBuckets'
        ng-options='opt as opt.name for opt in buckets'
        ng-model='bucketSelected' ng-change='changeBucket()'
        data-source-promise='bucketsPromise'>
</select>


来源:https://stackoverflow.com/questions/26218602/apply-kendo-dropdownlist-style-only-on-angular-select

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