用于角度1.2的debugInfoEnabled [英] debugInfoEnabled for Angular 1.2
问题描述
Angular 1.3引入了一个新的 debugInfoEnabled()
方法,如果在 false 进行调用,可以提高性能。 #disabling-debug-data>应用程序配置功能:
Angular 1.3 introduced a new debugInfoEnabled()
method that can provide a boost in performance if called with false
in the application config function:
myApp.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
此外,Angular 1.3还支持IE8。这对我来说是个问题,我的应用程序必须运行在IE8上。因此,我无法升级到角度1.3,必须使用1.2。
Also, Angular 1.3 dropped IE8 support. And this is a problem for me, my application have to run on IE8. Hence, I cannot upgrade to angular 1.3 and have to live with 1.2.
有没有办法使用角度1.2实现相同的功能?
Is there a way to achieve the same functionality with angular 1.2?
特别地,至少有一部分 debugInfoEnabled()
可以执行:
In particular, at least a part of what debugInfoEnabled()
does:
- 阻止创建新code> ng-scope /
ng-isolation-scope
CSS类范围 - 不要将绑定数据和ng类CSS类附加到具有ngBind,ngBindHtml或{{...}}插值的元素
- prevent creation of
ng-scope
/ng-isolated-scope
CSS classes while creating new scopes - do not attach binding data and ng-class CSS class to elements with ngBind, ngBindHtml or {{...}} interpolations
作为一个可能的选项,我可以将angularjs仓库分叉并将功能返回到1.2。然后,使用fork维护上游的更新。
感谢任何指针。
推荐答案
使用底层的DOM setAttribute
方法来防止默认行为。我已经在另一个答案中修改了plunker:
Use the underlying DOM setAttribute
method to prevent the default behavior. I've edited the plunker in the other answer:
http://plnkr.co/edit/cMar0d9IbalFxDA6AU3e?p=preview
执行以下操作:
- 克隆DOM
setAttribute
原型方法 - 用一个支票
ng
调试属性 - 为
ng返回false
调试属性 - 返回正常情况
- Clone the DOM
setAttribute
prototype method - Override it with a check for
ng
debug attributes - Return false for
ng
debug attributes - Return as normal otherwise
使用如下:
/* 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);
}
将 HTMLElement
替换为元素
为IE8。
参考
Prototypes, Constructor Functions, and Taxidermy
文档对象模型原型,第2部分:访问者( getter / setter)支持
这篇关于用于角度1.2的debugInfoEnabled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!