javascript – 用于角度1.2的debugInfoEnabled

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

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...