在 Internet Explorer 7 上运行 AngularJS 应用程序 [英] Running AngularJS App on Internet Explorer 7

查看:34
本文介绍了在 Internet Explorer 7 上运行 AngularJS 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了确保 AngularJS 是否能在我需要的浏览器上运行,我做了一个简单的数据绑定演示,它在 Firefox、Chrome 和 IE8+ 上运行良好,但我还需要让它在 IE7 上运行.不幸的是,我无法让它发挥作用.它只显示带有花括号的 html,忽略 ng- 属性.

我检查了几个帖子 关于 AngularJS 在 Internet Explorer 上尝试了建议的修复,但在我的演示中没有任何效果.

这是我的演示的 HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><头><title>Angular IE7 测试</title><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><!--[如果是 IE 9]><script type="text/javascript" src="angularjs/html5shiv.js"></script><![endif]--><!--[如果是 IE 8]><script type="text/javascript" src="angularjs/json3.js"></script><![endif]--><脚本语言="JavaScript" src="angularjs/angular.min.js"></script><脚本语言="JavaScript" src="angularjs/test.js"></script><body class="ng-app"><div ng-controller="serversCtrl"><p>{{texto}}</p><表格边框=1"><tr><th>Col1</th><th>Col2</th><th>Col3</th></tr><tr ng-repeat="item in items"><td>{{item.col1}}</td><td>{{item.col2}}</td><td>{{item.col3}}</td></tr></tbody>

</html>

这是包含控制器和模型的 test.js javascript:

function serversCtrl($scope, $http, $location) {$scope.texto = "Texto dinamico";$scope.items = [{col1: "foo1", col2: "bar1", col3: "baz1"},{col1: "foo2", col2: "bar2", col3: "baz2"},{col1: "foo3", col2: "bar3", col3: "baz3"},{col1:foo4",col2:bar4",col3:baz4"},{col1:foo5",col2:bar5",col3:baz5"}];}

我做错了吗?有没有其他我错过的技巧可以让它发挥作用?

我使用的是 AngularJS v1.0.5

解决方案

阅读更多内容后,我可以让它发挥作用.

IE7 的问题在于引导.它没有开火!所以我做了一个手动初始化,如这个页面所示,并且成功了.

这是我添加到 HTML 中的代码,确保它只会在 Internet Explorer 8 或更低版本上触发(因为如果我为所有浏览器触发它,一些事件处理程序会为非 IE 浏览器触发两次):