指令不会在 IE11 中工作
Directive wont work in IE11
我在 IE11 中使用此指令遇到了一些问题(注意:在 Edge、Chrome 和 Firefox 上,一切正常)。
如果我在返回对象之前发出警报,我在 IE 中没有它,我在其他浏览器中得到了两次(但无论如何没关系)。
Angular 版本为 1.5.3
.directive("cartBtnQty", function($rootScope) {
return {
restrict: "E",
scope :{
articleQuantity: '@',
lineNumber: '@'
},
replace: true,
link: function(scope, elem, attr, form) {
alert('directive');
elem.bind('click keydown', function (e) {
$operator = null;
// click button +/-
$operator = angular.element(e.target).data('operator')
if($operator == '+')
scope.articleQuantity = parseInt(scope.articleQuantity)+1;
else if($operator == '-' && scope.articleQuantity > 1)
scope.articleQuantity = parseInt(scope.articleQuantity)-1;
// limitation pour quantité négative
if(scope.articleQuantity < 1)
scope.articleQuantity = parseInt(1);
if((e.type == 'click' && ($operator == '-' || $operator == '+')) || e.type == 'keydown'){
$rootScope.cartQtyItem({articleQuantity:scope.articleQuantity, lineNumber:scope.lineNumber});
return true;
}
});
},
template: '<div class="ui right mini action input">'+
'<form><input type="text" ng-model="articleQuantity" ng-init="articleQuantity=articleQuantity" class="w30"/>'+
'<div class="ui icon buttons mini">'+
'<button class="ui button" data-operator="+"><i class="plus icon" data-operator="+"></i></button>'+
'<button class="ui button grey" data-operator="-"><i class="minus icon" data-operator="-"></i></button>'+
'</div></form></div>'
};
})
我看到两个问题:
- 缺少变量声明(顺便说一句,你不应该使用 $ 作为局部变量)
var $operator = null
- 尝试使用
attr
而不是 data
:angular.element(e.target).attr('data-operator');
根据该指令,alert 在 IE 中应该可以正常工作。
Aleksey Solovey 很好。我切换到适当的 class,老开发人员在 DOM 中添加了一些 isIe() 函数。谢谢你们的时间。
我在 IE11 中使用此指令遇到了一些问题(注意:在 Edge、Chrome 和 Firefox 上,一切正常)。
如果我在返回对象之前发出警报,我在 IE 中没有它,我在其他浏览器中得到了两次(但无论如何没关系)。
Angular 版本为 1.5.3
.directive("cartBtnQty", function($rootScope) {
return {
restrict: "E",
scope :{
articleQuantity: '@',
lineNumber: '@'
},
replace: true,
link: function(scope, elem, attr, form) {
alert('directive');
elem.bind('click keydown', function (e) {
$operator = null;
// click button +/-
$operator = angular.element(e.target).data('operator')
if($operator == '+')
scope.articleQuantity = parseInt(scope.articleQuantity)+1;
else if($operator == '-' && scope.articleQuantity > 1)
scope.articleQuantity = parseInt(scope.articleQuantity)-1;
// limitation pour quantité négative
if(scope.articleQuantity < 1)
scope.articleQuantity = parseInt(1);
if((e.type == 'click' && ($operator == '-' || $operator == '+')) || e.type == 'keydown'){
$rootScope.cartQtyItem({articleQuantity:scope.articleQuantity, lineNumber:scope.lineNumber});
return true;
}
});
},
template: '<div class="ui right mini action input">'+
'<form><input type="text" ng-model="articleQuantity" ng-init="articleQuantity=articleQuantity" class="w30"/>'+
'<div class="ui icon buttons mini">'+
'<button class="ui button" data-operator="+"><i class="plus icon" data-operator="+"></i></button>'+
'<button class="ui button grey" data-operator="-"><i class="minus icon" data-operator="-"></i></button>'+
'</div></form></div>'
};
})
我看到两个问题:
- 缺少变量声明(顺便说一句,你不应该使用 $ 作为局部变量)
var $operator = null
- 尝试使用
attr
而不是data
:angular.element(e.target).attr('data-operator');
根据该指令,alert 在 IE 中应该可以正常工作。
Aleksey Solovey 很好。我切换到适当的 class,老开发人员在 DOM 中添加了一些 isIe() 函数。谢谢你们的时间。