0

I have in an angular component this piece of code:

  @Output() fixPercentChanged = new EventEmitter<number>();

And I have this event:

fixChanged(e) {
    setTimeout(() => {
      let fix = e.component.option('value');
      this.fixPercentChanged.emit(100 - fix);
    }, 100); 
  }

This event is binded in the markup to a keydown event of an input element:

<dxi-item dataField="fix" [label]="{text: 'Fix %'}" editorType="dxNumberBox"
                [editorOptions]="{format: '#,##0.00\'%\'', onKeyDown: fixChanged, valueChangeEvent: 'keyup'}">
        <dxi-validation-rule type="required" message="A mező kitöltése kötelező"></dxi-validation-rule>
      </dxi-item>

It gets fired, but the console says, that fixPercentChanged is undefined. If I print this to the console, I get the dx-number-box input element. this should refer in this case to the component itself. How to rewrite the function in oder to correct this?

derstauner
  • 1,478
  • 2
  • 23
  • 44

1 Answers1

0

@jonrsharpe, your link pointed out the issue. This is the right syntax:

  fixChanged = (e) => {
    setTimeout(() => {
      let fix = e.component.option('value');
      this.fixPercentChanged.emit(100 - fix);
    }, 100); 
  }

Now, this refers to the component itself and the event gets emitted.

derstauner
  • 1,478
  • 2
  • 23
  • 44