更改默认更改检测策略 [英] Change default change detection strategy
本文介绍了更改默认更改检测策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将默认更改检测策略设置为 OnPush
?可以以某种方式在全局设置它吗?
How to set the default change detection strategy to OnPush
? Can it be set globally somehow?
我要避免不必将此行添加到每个组件中
I want to avoid having to adding this line to every component
@Component({
...
changeDetection: ChangeDetectionStrategy.OnPush,
...
})
推荐答案
更改检测策略只能针对每个组件或指令定义,而不能全局定义。
The change detection strategy can only be defined per component or directive not globally.
使用自定义装饰器,因为即将发布的脱机模板编译器将不支持它。
Using a custom decorator is discouraged because it will not be supported by the upcoming offline template compiler.
这篇关于更改默认更改检测策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文