Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS Routing not working in IE7

Tags:

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?

like image 691
Tom Avatar asked Oct 03 '12 13:10

Tom


1 Answers

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>
like image 197
adrien Avatar answered Sep 17 '22 19:09

adrien