Angular 使ChangeDetectionStrategy可由组件使用者配置
假设UI库中有一个组件使用Angular 使ChangeDetectionStrategy可由组件使用者配置,angular,angular-changedetection,Angular,Angular Changedetection,假设UI库中有一个组件使用ChangeDetectionStrategy.Default,但希望通过Input()属性为消费者提供使用ChangeDetectionStrategy.OnPush的选项(例如,对于性能敏感的情况) 是否可以在运行时更改组件的更改检测策略?或者只能在@组件装饰器中设置它?可以从'@angular/core'注入ChangeDetectorRef,并在通过输入()属性触发的函数中调用detectChanges() // Import import { ChangeDe
ChangeDetectionStrategy.Default
,但希望通过Input()
属性为消费者提供使用ChangeDetectionStrategy.OnPush
的选项(例如,对于性能敏感的情况)
是否可以在运行时更改组件的更改检测策略?或者只能在
@组件
装饰器中设置它?可以从'@angular/core'注入ChangeDetectorRef,并在通过输入()属性触发的函数中调用detectChanges()
// Import
import { ChangeDetectorRef } from '@angular/core';
//Constructor
constructor(private cdr: ChangeDetectorRef) { }
//Function
input() {
this.cdr.detectChanges();
}