1

我想将 ngChange 事件绑定到工具栏选项中定义的日期选择器 kendo-date-picker,但是 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

4

1 回答 1

0

您正在使用 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');}
    }
  }
 });
于 2016-12-19T06:12:31.910 回答