angularjs NG-变化不会得到NG-模型的onblur指令在IE9和10发射 [英] angularjs ng-change doesn't get fired on ng-model-onblur directive in IE9 and 10

查看:670
本文介绍了angularjs NG-变化不会得到NG-模型的onblur指令在IE9和10发射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NG-模型上的模糊指令(从<复制的一个输入文本框href=\"http://stackoverflow.com/questions/11868393/angularjs-inputtext-ngchange-fires-while-the-value-is-changing/11870341#11870341\">Angularjs:输入[文] ngChange火灾而值正在改变)与连接到它NG-change事件处理函数。它为当用户键入的开箱它触发连接到NG-改变功能的伟大工程。我修改了链接功能,所以它也结合上的变化和粘贴事件。

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());
            });
        });
    }

我有一个从打开其中一个用户可以输入一些东西,然后调用值返回到输入文本框父页面上的弹出页面,页面上的按钮。在大多数其他浏览器(Chrome浏览器,火狐,Safari,甚至IE8 ..)当从弹出接收到输入文本框中输入数据,但NG-变化打响了IE9和10毫微克变化,不会触发时数据被从弹出接收。该指令调用NG变功能时,用户类型出了场,手工粘贴数据,或者通过右键单击文本框,但是当数据从弹出来它不火的功能。

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.

弹出不使用AngularJS但窗口对象的opener属性的值传送到输入文本框。

The popup doesn't use AngularJS but opener property of the window object to transfer the value to the input text box.

任何帮助将大大AP preciated!

Any help would be greatly appreciated!

推荐答案

我是能够解决的,因为更改事件是从父页面元素在弹出的页面触发的方式的问题。设置opener.parentElement.value =为newValue后弹出的页面;正在执行parentElement.fireEvent('变化'),如果document.createEventObject是真实的,否则它正在执行parentElement.dispatchEvent()用于非IE浏览器。

I was able to solve the issue because of the way the change event was triggered from the popup page on the parent page element. The popup page after setting opener.parentElement.value = newValue; was executing parentElement.fireEvent('change') if document.createEventObject was true, else it was executing parentElement.dispatchEvent() for non-IE browsers.

MS介绍DOM 2级事件与IE9,因此fireEvent没有被在IE> = 9浏览器的支持。由于document.createEventObject仍然如此IE> = 9这是我的指令执行elm.bind和fireEvent因此,('变')没有得到触发。我改变了我的弹出的JavaScript文件:

MS introduced DOM Level 2 events with IE9 and hence fireEvent was not being supported in IE >=9 browsers. Since document.createEventObject was still true for IE>=9 it was executing fireEvent and hence in my directive elm.bind('change') was not getting triggered. I changed my popup javascript file to:

if(element.dispatchEvent) {
    //IE >= 9 and other browsers event code
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true );
    return element.dispatchEvent(evt);
}
else if(element.fireEvent){
    //IE < 9
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt);
}

和NG-变化开始触发针对IE> = 9也。这篇文章为什么.fireEvent()不是在IE9工作?的帮助我理解这个问题,并解决它。

and ng-change began triggering for IE >= 9 also. This post Why does .fireEvent() not work in IE9? helped me in understanding the problem and solving it.

由于这再次社区真棒!

这篇关于angularjs NG-变化不会得到NG-模型的onblur指令在IE9和10发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆