javascript更改事件在angularjs上不起作用

javascript更改事件在angularjs上不起作用,angularjs,Angularjs,我正在探索jqLite,并试图了解AngularJS在执行DOM操作和普通JavaScript时是如何工作的。基本上,我一直在尝试将事件绑定到不同的元素,到目前为止效果很好。模糊、聚焦、mouseenter、mouseleve它们在对元素执行.on('event',handler)操作时都有效,但输入字段中的'change'元素除外 angular .module('app') .directive('jqLite', jqLite); /* @ngInject */ func

我正在探索jqLite,并试图了解AngularJS在执行DOM操作和普通JavaScript时是如何工作的。基本上,我一直在尝试将事件绑定到不同的元素,到目前为止效果很好。模糊、聚焦、mouseenter、mouseleve它们在对元素执行.on('event',handler)操作时都有效,但输入字段中的'change'元素除外

angular
    .module('app')
    .directive('jqLite', jqLite);

/* @ngInject */
function jqLite () {

    return {
        scope: {},
        restrict: 'E',
        template: [
            '<h1>jqLite</h1>',
            '<input type="text" ng-change="onChange()" ng-model="jqLiteInput">',
            '<span style="background: red;">#<span>',
            '<!-- a comment -->'
        ].join(''),
        link: function (scope, element, attrs) {

            var input = element.find('input');

            /* AngularJS also has directives like
            ng-blur ng-focus ng-mouseenter ng-mouseleave but I can bind all of these events
            with .bind() or .on() method as I would usually do on jQuery */

            input.on('focus', function () { console.log(element.contents()); });
            input.on('blur', function () { console.log(element.html()); });

            //input.on('change', function () { console.log('this does not work'); });

            // this works
            scope.onChange = function () { console.log(scope.jqLiteInput + ' ' + element.children()); };

        }
    };

}
angular
.module('应用程序')
.指令(“jqLite”,jqLite);
/*@ngInject*/
函数jqLite(){
返回{
作用域:{},
限制:'E',
模板:[
“jqLite”,
'',
'#',
''
].加入(“”),
链接:函数(范围、元素、属性){
var input=element.find('input');
/*AngularJS还有如下指令
ng blur ng focus ng mouseenter ng mouseleave但我可以绑定所有这些事件
使用.bind()或.on()方法,就像我通常在jQuery上所做的那样*/
on('focus',function(){console.log(element.contents());});
on('blur',function(){console.log(element.html());});
//on('change',function(){console.log('this not work');});
//这很有效
scope.onChange=function(){console.log(scope.jqLiteInput+''+element.children());};
}
};
}

这真的很奇怪,我希望有人能给我一些提示。

您希望输入字段什么时候触发
change
事件?当值更改时,这不是更改的目的吗?另外,当select元素的值发生变化时,这里似乎可以正常工作:如果您想在值发生变化时运行change函数,请使用keyup事件,而不是keyup事件抱歉,我完全误解了这里的变化。我知道为什么改变看起来不起作用,因为只有当你模糊输入字段时,它才会启动。我完全错过了这个!谢谢大家!