Hello I have strange issue that only appears in IE 11 with angular 1.3.
I have a directive which allows me to store Object
as ngModel
value of input
element. It works without any problem with AngularJS 1.2, but it doesn't work with AngularJS 1.3 (only in the Internet Explorer).
It is simply code:
elem.on('input', function(){
var val = elem.val();
ngModel.$setViewValue({
'sampleData': new Date().getTime(),
'value': val
});
scope.$apply();
});
When I type text in IE, the input sets correct object as model value for some milliseconds but next changes it into string. In other browsers it updates ngModel
correctly.
You can see this strange behavior there:
AngularJS 1.2: / (works in IE, Chrome, and Firefox),
AngularJS 1.3: / (doesn't work in IE 11, works in Chrome and Firefox)
What is the reason and how can I fix it?
It is my whole directive:
app.directive('myInput',function(){
return{
restrict: 'A',
require: 'ngModel',
scope: {},
priority: 1,
link: function(scope, elem, attrs, ngModel){
elem.off('input');
elem.off('change');
ngModel.$render = function(){
var model = {
'sampleData': 'sampleData',
value: ''
}
ngModel.$setViewValue(model);
elem.val(model.value);
}
elem.on('input', function(){
var val = elem.val();
ngModel.$setViewValue({
'sampleData': new Date().getTime(),
value: val
});
scope.$apply();
});
}
}
});
Hello I have strange issue that only appears in IE 11 with angular 1.3.
I have a directive which allows me to store Object
as ngModel
value of input
element. It works without any problem with AngularJS 1.2, but it doesn't work with AngularJS 1.3 (only in the Internet Explorer).
It is simply code:
elem.on('input', function(){
var val = elem.val();
ngModel.$setViewValue({
'sampleData': new Date().getTime(),
'value': val
});
scope.$apply();
});
When I type text in IE, the input sets correct object as model value for some milliseconds but next changes it into string. In other browsers it updates ngModel
correctly.
You can see this strange behavior there:
AngularJS 1.2: http://jsfiddle/aartek/e6Lvpqj3/ (works in IE, Chrome, and Firefox),
AngularJS 1.3: http://jsfiddle/aartek/mvx9dbyu/2/ (doesn't work in IE 11, works in Chrome and Firefox)
What is the reason and how can I fix it?
It is my whole directive:
app.directive('myInput',function(){
return{
restrict: 'A',
require: 'ngModel',
scope: {},
priority: 1,
link: function(scope, elem, attrs, ngModel){
elem.off('input');
elem.off('change');
ngModel.$render = function(){
var model = {
'sampleData': 'sampleData',
value: ''
}
ngModel.$setViewValue(model);
elem.val(model.value);
}
elem.on('input', function(){
var val = elem.val();
ngModel.$setViewValue({
'sampleData': new Date().getTime(),
value: val
});
scope.$apply();
});
}
}
});
Angular 1.3 has some kind of hack for input
event for IE browsers. Please analyse $SnifferProvider.hasEvent
function. This function is used within inputDirective to guarantee the correct viewValue for browsers which does not support input
event. Workaround is based on keydown
event which is widely supported.
To fix your code example for IE simple turn of keydown
event to disable all triggers.
link: function(scope, elem, attrs, ngModel){
elem.off('input');
elem.off('change');
elem.off('keydown');
...