Angular 1.3引入了一种新的
debugInfoEnabled()
方法,可以提高性能,如果在
application config function:
- myApp.config(['$compileProvider',function ($compileProvider) {
- $compileProvider.debugInfoEnabled(false);
- }]);
此外,Angular 1.3支持IE8.这对我来说是个问题,我的应用程序必须在IE8上运行.因此,我不能升级到角度1.3,必须生活在1.2.
有没有办法用角度1.2实现相同的功能?
特别是debugInfoEnabled()的至少一部分:
>在创建新的范围时,阻止创建ng范围/ ng隔离范围的CSS类
>不要使用ngBind,ngBindHtml或{{…}}插值将绑定数据和ng类CSS类附加到元素
作为一个可能的选择,我可以将angularjs仓库分叉并将功能返回到1.2.然后,使用fork维护上游的更新.
会感激任何指针.
解决方法
使用底层的DOM setAttribute方法来防止默认行为.我在另一个答案中编辑了这个plunker:
http://plnkr.co/edit/cMar0d9IbalFxDA6AU3e?p=preview
做以下事情:
>克隆DOM setAttribute原型方法
>通过检查调试属性来覆盖它
>返回false为ng调试属性
>返回正常
使用如下:
- /* Clone the original */
- HTMLElement.prototype.ngSetAttribute = HTMLElement.prototype.setAttribute;
- /* Override the API */
- HTMLElement.prototype.setAttribute = function(foo,bar) {
- /* Define ng attributes */
- var nglist = {"ng-binding": true,"ng-scope":true,"ng-class":true,"ng-isolated-scope":true};
- console.log([foo,bar]);
- /* Block ng attributes; otherwise call the clone */
- if (nglist[foo])
- return false;
- else if (JSON.stringify(nglist).match(foo) )
- return false;
- else
- return this.ngSetAttribute(foo,bar);
- }
用IE8替换元素的HTMLElement.
参考
> CSS classes used by angular
> Prototypes,Constructor Functions,and Taxidermy
> AngularJS IE8 Shim
> AngularJS IE8 Builds
> Document Object Model Prototypes
> Document Object Model Prototypes,Part 2: Accessor (getter/setter) Support
> What’s New in Internet Explorer 9