AngularJS Routing not working in IE7

Tom picture Tom · Oct 3, 2012 · Viewed 10k times · Source

I have been implementing Routing in my app following the tutorial

http://docs.angularjs.org/tutorial/step_07

I couldn't get my version to work in IE7, and after spending a while trying to work out what I have missed / done wrong I have noticed that the example doesn't work.

http://angular.github.com/angular-phonecat/step-7/app/

Anyone know how to get this to work?

Answer

adrien picture adrien · Oct 15, 2012

OK I had the same problem so I started the bounty, but after that I found the working solution (for me at least):

  • Use HTML5 shim
  • Use JSON2.js
  • Add all these attributes to your html node:

    class="ng-app:myapp" id="ng-app" ng-app="myapp" xmlns:ng="http://angularjs.org"

(where myapp is really your app name)

So to recap, here is my IE7/8/9 working HTML page:

<!DOCTYPE html>
<html lang="en" class="ng-app:myapp" id="ng-app" ng-app="myapp" xmlns:ng="http://angularjs.org">
  <head>
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <!--[if lte IE 8]>
      <script>
        document.createElement('ng-include');
        document.createElement('ng-pluralize');
        document.createElement('ng-view');
        document.createElement('ng:include');
        document.createElement('ng:pluralize');
        document.createElement('ng:view');
      </script>
    <![endif]-->
    <!--[if lt IE 8]>
      <script src="js/json2.js"></script>
    <![endif]-->
  </head>
  <body>
    <div ng-view></div>
  </body>
</html>