0

我有以下指令,我必须使用 nativelements.value 来避免一些只读错误

  @Input('key') key: string;
  @Input('component') component: string;
  constructor(
    private store: Store,
    private elementRef: ElementRef<HTMLInputElement>,
    private elementRefMatSelect: ElementRef<HTMLSelectElement>
  ) {
    this.key = '';
    this.component = '';
  }
  @HostListener('change') onChange() {
    console.log('noticed something');

    this.store.dispatch<IAction<IAdjust>>({
        type: RDX_DELIVERY_ACROSS_ADJUST,
        payload: {
          key: this.key,
          value: this.elementRef.nativeElement.value
        },
        component: this.component
      })
  }
  @HostListener('selectionChange') onSelectionChange() {
    console.log('noticed something');

    this.store.dispatch<IAction<IAdjust>>({
        type: RDX_DELIVERY_ACROSS_ADJUST,
        payload: {
          key: this.key,
          value: this.elementRefMatSelect.nativeElement.value
        },
        component: this.component
      })
  }

onlythis.elementRefMatSelect.nativelement.value是空的,我如何在指令中获取 mat-select 的值

4

0 回答 0