【问题标题】:ngChange doesn't work for kendo-date-picker which defined in kendo.toolbarOptionsngChange 不适用于 kendo.toolbarOptions 中定义的 kendo-date-picker
【发布时间】:2017-05-04 03:27:26
【问题描述】:

我想将ngChange事件绑定到kendo-date-picker,即toolbarOptions中定义的日期选择器,但是ngChange不起作用。

 $scope.toolbarOptions = {
        items: [{
            template: "<label>From</label>"
        }, {
            template: "<input id='start' kendo-date-picker ng-model='dateString' k-ng-model='dateObject' ngChange='startChange()' />",
            overflow: "never"
        }]};

 $scope.startChange = function() {console.log('changed');}
 
 function startChange() {console.log('changed');}

请检查我的代码,两个 startChange 都不起作用。有一个 ReferenceError: startChange is not defined

【问题讨论】:

    标签: angularjs kendo-ui telerik angularjs-ng-change kendo-datepicker


    【解决方案1】:

    您正在使用 ngChange,请使用 ng-change 进行更改,例如:-

    $scope.toolbarOptions = {
        items: [{
            template: "<label>From</label>"
        }, {
            template: "<input id='start' kendo-date-picker ng-model='dateString' k-ng-model='dateObject' ng-change='startChange()' />",
            overflow: "never"
        }]};
    
        $scope.startChange = function() {console.log('changed');}
    

    或者如果你想调用 javascript 函数,那么你必须在使用之前定义你的 js 函数

      angular.module("KendoDemos", [ "kendo.directives" ])
      .controller("MyCtrl", function($scope){
    
            $scope.toolbarOptions = {
              items: [{
                 template: "<label>From</label>"
                }, {
                template: "<input id='start' handle-change kendo-date-picker ng-model='dateString' k-ng-model='dateObject' onChange='startChange()' />",
            overflow: "never"
              }]
    
            };
        }).directive('handleChange',function(){
        return{
           link:function(scope,ele,attr){
             //you can use this
                //ele.on('change',function(){
                  //alert(555)
               //})
          //or
          function startChange() {console.log('changed');}
        }
      }
     });
    

    【讨论】:

    • 尝试了第二个解决方案,仍然抛出异常 startChange is not defined
    • 你可以尝试新的更新代码,添加“handle-change”指令
    • 感谢您的回复。我的控制器很大,toolbarOptions里面还有很多其他的项目,有没有优雅的方法?
    • 您可以在父 div 中使用此指令,例如
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    相关资源
    最近更新 更多