错误TypeError:无法读取未定义的属性“调用”

时间:2020-06-02 07:45:53

标签: angular angular9 nouislider

我终于开始在我的angular 9项目中使nouislider工作。现在的问题是,当滑块值更改时,我想更新一个字段(因此,当用户移动滑块时,我想在屏幕上显示新值)。这些事件有问题,我不确定这是什么。

noUiSlider.create(this.theHtmlElement, {
  start: [3000],
  step: 1,
  connect: [true, false],
  range: {
      'min': [0],
      'max': [10000]
  }
});

this.theHtmlElement.noUiSlider.on('update', this.valueChanged());


...
valueChanged() {
console.log(this.theHtmlElement.noUiSlider.get());

}

我得到的错误是:

ERROR TypeError: Cannot read property 'call' of undefined
at nouislider.js:2082
at Array.forEach (<anonymous>)
at nouislider.js:2081
at Array.forEach (<anonymous>)
at fireEvent (nouislider.js:2077)
at nouislider.js:2055
at Array.forEach (<anonymous>)
at Object.bindEvent [as on] (nouislider.js:2054)
at AddCreditPageComponent.ngAfterViewInit (add-credit-page.component.ts:65)
at callProviderLifecycles (core.js:33986)

该事件似乎第一次起作用,我在控制台中看到了初始值,但随后出现错误!然后没有其他工作。我进行了一次遍历,似乎有第二个未定义的范围事件!不知道它是什么,它是从哪里来的,可能就是那引起了问题。我不确定该如何解决。

1 个答案:

答案 0 :(得分:2)

要绑定事件,您必须传入匿名函数(在其他可能性中);

File "C:\Users\Mike\AppData\Local\Programs\Python\Python38-32\lib\site-packages\scipy\misc\common.py", line 119, in derivative
val += weights[k]*func(x0+(k-ho)*dx,*args)
TypeError: <lambda>() missing 2 required positional arguments: 'popul_num' and 'stoch_rate'

this.theHtmlElement.noUiSlider.on('update', () => this.valueChanged());

this.theHtmlElement.noUiSlider.on('update', this.valueChanged.bind(this));

您的操作方式如何立即执行this.theHtmlElement.noUiSlider.on('update', this.valueChanged); readonly valueChanged = () => { console.log(this.theHtmlElement.noUiSlider.get()); }; 方法,该方法返回this.valueChanged()。然后,它将尝试将此undefined绑定到undefined事件处理程序,这将导致您看到的错误