-->

ng-grid not working in IE8

2019-05-22 12:59发布

问题:

I'm going nuts trying to figure out why ng-grid isn't working in IE8. I get this error: Expected identifier, string or number ng-grid-2.0.5.debug.js, line 1535 character 17.

I'm copying an example straight from the ng-grid homepage (all the examples there load correctly, by the way). Anyone have an idea here?

I would put up a Plnkr or fiddle, but neither will even load in IE8, so it kind of defeats the purpose.

using Angular 1.0.4, jQuery 1.8.1, ng-grid 2.0.5

html

<html ng-app="myApp">  
<head lang="en">
    <meta charset="utf-8">
    <title>Getting Started With ngGrid Example</title>  
    <link rel="stylesheet" type="text/css" href="ng-grid.css" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script type="text/javascript" src="jquery-1.8.1.js"></script>
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="ng-grid-2.0.5.js"></script>
    <script type="text/javascript" src="main.js"></script>
</head>
<body ng-controller="MyCtrl">
    <div class="gridStyle" ng-grid="gridOptions"></div>
</body>

CSS

.gridStyle {
  border: 1px solid rgb(212,212,212);
  width: 400px; 
  height: 300px;
}

Javascript

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.myData = [{name: "Moroni", age: 50},
                     {name: "Tiancum", age: 43},
                     {name: "Jacob", age: 27},
                     {name: "Nephi", age: 29},
                     {name: "Enos", age: 34}];
    $scope.gridOptions = { 
        data: 'myData',
        columnDefs: [{field:'name', displayName:'Name'}, {field:'age', displayName:'Age'}]
    };
});

回答1:

Turns out the answer was not so obvious. There was a bug in ng-grid 2.0.5 where the devs were using the Javascript forEach method in one spot instead of angular.forEach. This is not supported by IE8 and was causing the error. I submitted it to the group and they'll fix it, but for now I just made the change.



回答2:

Internet Explorer requires special treatment for accommodating AngularJS. Please read this.

http://docs.angularjs.org/guide/ie