Angular Component的默认changeDetection策略
生活随笔
收集整理的這篇文章主要介紹了
Angular Component的默认changeDetection策略
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
默認策略為:ChangeDetectionStrategy.Default:
實現代碼:
/*** Type of the Directive metadata.** @publicApi*/ const Directive = makeDecorator('Directive', ?0$e, undefined, undefined, ?1$3); const ?2$1 = (c = {}) => (Object.assign({ changeDetection: ChangeDetectionStrategy.Default }, c)), ?3$1 = (type, meta) => SWITCH_COMPILE_COMPONENT(type, meta); /*** Component decorator and metadata.** @Annotation* @publicApi*/ const Component = makeDecorator('Component', ?2$1, Directive, undefined, ?3$1); const ?4 = (p) => (Object.assign({ pure: true }, p)), ?5 = (type, meta) => SWITCH_COMPILE_PIPE(type, meta); /*** @Annotation* @publicApi*/ const Pipe = makeDecorator('Pipe', ?4, undefined, undefined, ?5); const ?6 = (bindingPropertyName) => ({ bindingPropertyName }); /*** @Annotation* @publicApi*/ const Input = makePropDecorator('Input', ?6); const ?7 = (bindingPropertyName) => ({ bindingPropertyName }); /*** @Annotation* @publicApi*/ const Output = makePropDecorator('Output', ?7); const ?8 = (hostPropertyName) => ({ hostPropertyName }); /*** @Annotation* @publicApi*/ const HostBinding = makePropDecorator('HostBinding', ?8); const ?9 = (eventName, args) => ({ eventName, args });在SAP Spartacus大多數Component里,我們都用@Component將changeDetection顯式指定成ChangeDetectionStrategy.OnPush:
而OnPush是另一種策略,用于提高Angular 應用的性能。
在OnPush工作模式下,只有input ref change和output’s call會觸發change detection機制。
TestBed.overrideComponent提供了一種能夠覆蓋標準ChangeDetectionStrategy的機制。
更多Jerry的原創文章,盡在:“汪子熙”:
總結
以上是生活随笔為你收集整理的Angular Component的默认changeDetection策略的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 笔记本分游戏本和什么本(高端轻薄本和高端
- 下一篇: js计算器(正则)