Thursday, February 28, 2013

IE7 don't have feelings, but it's a browser too


Having said that, it still needed be supported by JavaScript frameworks too despite IE10’s release


Yesterday I shared that AngularJS is not compatible with IE7 to colleague engineers during my AngularJS presentation, I should have been more creative on answering that given that I said JavaScript can even emulate x86 instruction set. JavaScript is a better VM than Java on this regard, I digress 



AngularJS is not incompatible to IE7 per se, it can’t work on IE7 out-of-the-box as string data type is the only type supported by IE7's JSON library. Enter JSON polyfill, it will plug the gaping hole of IE7's lack of native JSON library


Just use json3.min.js polyfill to make IE7 work with AngularJS:


<script src="angular.min.js"></script>
<!--<script src="json3.min.js"></script>-->

    
<body class="ng-app:myApp" id="ng-app">

       <div ng-app='myApp'>
              <div ng-controller="MyCtrl">
              1. Hello, {{title}}!           <input  ng-model="title" type="text" /><br/>
              2. Hello, {{hero.name}}!        <input  ng-model="hero.name" type="text" /><br/>
              3. Hello, {{hero.rescued}}!     <input  ng-model="hero.rescued" type="text" /><br/>
              4. Hello, {{hero.birthday}}!    <input  ng-model="hero.birthday" type="text" /><br/>   
              </div>
       </div>

</body>


<script>
    angular.module('myApp', []).controller(MyCtrl);

    function MyCtrl($scope) {
        $scope.title = 'Man of Steel';
        $scope.hero = { name: 'Superman', rescued: 1337, birthday: new Date(2000, 1, 27, 0, 0, 0, 0) };
    }
</script>






It turns out one of our projects is using JSON polyfill, I surmise for IE7 compatibility too, albeit using version 2 only, json2.js


Open the above code on IE7, you'll see that number and date doesn't bind. Then include json3.min.js, number and date will bind 





Happy Coding! 

No comments:

Post a Comment