嗨,我在这种情况下:
以下组件的QueryList
始终为空,而changes Observable
永不触发,
该组件通过角CDK Overlay
@Component({
selector: 'app-color-picker',
templateUrl: './color-picker.component.html',
styleUrls: ['./color-picker.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ColorPickerComponent
implements AfterViewInit, OnDestroy {
@ViewChildren(ColorComponent) colorComponents: QueryList<ColorComponent>;
/* Other stuff */
ngAfterViewInit(): void {
console.log(this.colorComponents); // <---- Empty!
this.colorComponents.changes.subscribe((ch) => console.log(ch)); <-- never fire!
}
ngOnDestroy(): void {
}
}
如果我移除了changeDetection: ChangeDetectionStrategy.OnPush
可观察到的火,
使用changeDetection: ChangeDetectionStrategy.OnPush
时如何访问QueryList