Search code examples
angularjsangular-directive

Directive wont work in IE11


I encounter some troubles with this directive in IE11 (note : on Edge, Chrome et Firefox, everything works fine).

If I place an alert just before returning the object, i dont have it in IE, and I got twice in other browser (but it's ok anyway).

Angular version is 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>'
};

})


Solution

  • Aleksey Solovey was good. I switch the to a proper class, and the old developer add some isIe() functions in the DOM. Thank you for your time guys.