Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-class if browser is not internet explorer

I have an issue, i want to add a css class to an item only if the browser isn't internet explorer.

Can I do that with Angular JS?

something like:

<div ng-class="myClass : "BROWSER IS IE" ? default"><div>

SOLUTION:

HTML:

       <div data-ng-class="getClass()"></div>

JAVASCRIPT:

        $scope.isIe = function () {
            return false || !!document.documentMode;
        }

        $scope.getClass = function () {
            if ($scope.isIe()) {
                return "";
            }
            else {
                return "yourClass1 yourClass2 yourClass3";
            }
        }
like image 911
xechelonx Avatar asked Nov 28 '25 10:11

xechelonx


1 Answers

You could assign the class via a function like:

data-ng-class="getClass()"

In getClass() implement functionality to detect IE and return the empty string if it is detected, but return a space separated list of class name(s) if it is not. Something like:

EDIT: add function isIe based on comment by @jsonmurphy

function isIe() {
  return false || !!document.documentMode;
}

$scope.getClass = function() {
  if(isIe()) {
    return "";
  }
  else {
    return "className1 className2 ... ";
  }
}

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!