Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS works in Chrome, but not IE 11

I'm picking up Angular JS at: http://www.sitepoint.com/practical-guide-angularjs-directives/, and I find that the following codes work in Chrome, but not IE 11.

<!DOCTYPE html>
<html ng-app="myapp">
<head>
    <meta charset="utf-8" />
    <title>No Title</title>
    <script data-require="[email protected]" src="http://code.angularjs.org/1.2.7/angular.js" data-semver="1.2.7"></script>
</head>
<body>
    <input type="text" ng-model="color" placeholder="Enter a color..." />
    <div data-hello-world />
    <script>
        var app = angular.module('myapp', []);
        app.directive('helloWorld', function () {
            return {
                restrict: 'AE',
                replace: true,
                template: '<p style="background-color:{{color}}">Hello World!!</p>',
                link: function (scope, elem, attrs) {
                    elem.bind('click', function () {
                        elem.css('background-color', 'white');
                        scope.$apply(function () { scope.color = "white"; });
                    });
                    elem.bind('mouseover', function () { elem.css('cursor', 'pointer'); });
                }
            }
        });
    </script>
</body>
</html>

Specifically, the mouseover and click events work fine. However, the paragraph's background color doesn't in IE (the color never changes). It's ok in Chrome. Thanks!

like image 817
Dunnomuch Avatar asked May 19 '14 07:05

Dunnomuch


People also ask

Why Angular is not working in IE?

There can be numerous reasons why your Angular application is not working, including: Missing polyfills in polyfills. ts . Using a TypeScript target version which IE11 does not support.

Is Angular compatible with IE?

By default, Angular compiles ES6 or ES7. IE 11 only supports ES5.

Does Angular 13 support IE?

Angular 13 has dropped support for Internet Explorer 11. This will allow the framework to leverage the features of modern browsers, such as CSS variables and web animation, as well as native web APIs.

Does Google still support AngularJS?

AngularJS support has officially ended as of January 2022.


2 Answers

Could be because document compatibility. This worked for me:

Add this tag to web.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <clear />
        <add name="X-UA-Compatible" value="IE=10" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration> 
like image 82
Mark Avatar answered Oct 09 '22 01:10

Mark


I added the following to the head and it worked. its very similiar to what Mark said...just none asp.net specific:

<meta http-equiv="X-UA-Compatible" content="IE=11" />

i also found i needed to add respond and modernizer in a if statement for older versions of IE:

<!--[if lt IE 9]>
<script src="/Binders/Scripts/modernizr-2.8.3.js"></script>
<script src="/Binders/Scripts/respond.js"></script>
<![endif]-->
like image 21
James Gates R. Avatar answered Oct 09 '22 02:10

James Gates R.