如何在使用ChnageDetectionStrategy.OnPush时获取QueryList元素

时间:2019-06-01 17:45:47

标签: angular

嗨,我在这种情况下:

以下组件的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

0 个答案:

没有答案