用于Angular 1.2的debugInfoEnabled

ale*_*cxe 11 javascript debugging backport internet-explorer-8 angularjs

Angular 1.3引入了一种新debugInfoEnabled()方法,如果false应用程序配置函数中调用,它可以提高性能:

myApp.config(['$compileProvider', function ($compileProvider) {
    $compileProvider.debugInfoEnabled(false);
}]);
Run Code Online (Sandbox Code Playgroud)

此外,Angular 1.3放弃了IE8的支持.这对我来说是一个问题,我的应用程序必须在IE8上运行.因此,我无法升级到角度1.3并且必须使用1.2.

有没有办法用角度1.2实现相同的功能?

特别是,至少有一部分debugInfoEnabled()做了:

  • 在创建新范围时阻止创建ng-scope/ ng-isolated-scopeCSS类
  • 不要将绑定数据和ng-class CSS类附加到具有ngBind,ngBindHtml或{{...}}插值的元素

作为一种可能的选择,我可以分叉angularjs存储库并将该功能反向回1.2.然后,使用fork维护来自上游的更新.

非常感谢任何指针.

Pau*_*tte 5

使用基础DOM setAttribute方法来防止默认行为.我在另一个答案中编辑了plunker:

http://plnkr.co/edit/cMar0d9IbalFxDA6AU3e?p=preview

做以下事情:

  • 克隆DOM setAttribute原型方法
  • 通过检查ng调试属性来覆盖它
  • 对于ng调试属性,返回false
  • 否则正常返回

使用方法如下:

/* 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);
}
Run Code Online (Sandbox Code Playgroud)

更换HTMLElementElement的IE8.

参考