I have an input text box with a ng-model-on-blur directive(copied from Angularjs: input[text] ngChange fires while the value is changing) with a ng-change event handler attached to it. It works great as in when the user types out of the box it fires the function attached to ng-change. I modified the link function so it also binds on change and paste events.
link: function(scope, elm, attr, ngModelCtrl) {
if (attr.type === 'radio' || attr.type === 'checkbox') return;
if($sniffer.hasEvent('input')){
elm.unbind('input').unbind('keydown').unbind('change').unbind('paste');
}
else if($sniffer.hasEvent('change')){
elm.unbind('input').unbind('keydown').unbind('change').unbind('paste');
}
//IE8 doesn't recognize the input or change events and throws error on unbind input.
else{
elm.unbind('keydown').unbind('change').unbind('paste');
}
elm.bind('blur change paste', function() {
scope.$apply(function() {
ngModelCtrl.$setViewValue(elm.val());
});
});
}
I have a button on that page which opens a popup page from where a user can enter something and then transfer the value back to the input text box on the parent page. In most of the other browsers(Chrome, Firefox, Safari, even IE8..) the ng-change is fired when the data is received from the popup to the input text box but in IE9 and 10 ng-change isn't fired when data is received from popup. The directive is calling the ng-change function when user types out of the field, manually pastes the data or through right click on the text box but when the data is coming from the popup it doesn't fire the function.
The popup doesn't use AngularJS but opener property of the window object to transfer the value to the input text box.
Any help would be greatly appreciated!