简体   繁体   English

Angular 2 上 Wijmo 的 valueChanged 事件 + 数据绑定问题

[英]Issue with Wijmo's valueChanged event + data binding on Angular 2

I have the following code that runs a function whenever the user changes the value of the wj-input-time :我有以下代码,每当用户更改wj-input-time的值时,它都会运行一个函数:

@Component({
    selector: 'my-app',
    template: '<wj-input-time [step]="1" (valueChanged)="test()"></wj-input-time>'
})
export class AppComponent {

  test() {
    console.log('test');
  }

}

The above works fine but when I add data binding to the input the valueChanged event is fired when the app loads and also when the user simply clicks the input which is not the desired outcome:以上工作正常,但是当我向输入添加数据绑定时,当应用程序加载时以及用户只需单击不是所需结果的输入时,就会触发valueChanged事件:

@Component({
    selector: 'my-app',
    template: '<wj-input-time [(value)]="testDate" [step]="1" (valueChanged)="test()"></wj-input-time>'
})
export class AppComponent {

  testDate: Date = new Date();

  test() {
    console.log('test');
  }

}

I have spent a lot of time reading Wijmo's documentation but it was not helpful.我花了很多时间阅读 Wijmo 的文档,但没有帮助。 What am I missing or doing wrong?我错过了什么或做错了什么?

I'm using Angular 2 final and Wijmo 5.20162.211 eval我正在使用 Angular 2 final 和 Wijmo 5.20162.211 eval

Here's a Plunker that shows the issue (check the console log): http://plnkr.co/edit/RFo84NEUbypSWwPPu8Go?p=preview这是一个显示问题的Plunker(检查控制台日志): http ://plnkr.co/edit/RFo84NEUbypSWwPPu8Go?p=preview

Here's also screenshots:这里还有截图: 在此处输入图片说明 在此处输入图片说明

It's because the date that you've constructed is exact to the second, but the widget is only exact to the minute.这是因为您构建的日期精确到秒,而小部件只精确到分钟。 Because of this the widget rewrites the variable once it calculates the other values it needs - which is when you click the arrow button.因此,一旦它计算出它需要的其他值,小部件就会重写该变量 - 即当您单击箭头按钮时。

If you construct a date that is exact only to the given minute, the second log message does not appear anymore.如果您构建的日期仅精确到给定的分钟,则第二条日志消息将不再出现。

@Component({
  selector: 'my-app',
  template: '<wj-input-time [(value)]="testDate" [step]="1" (valueChanged)="test()"></wj-input-time>'
})
export class AppComponent {

  testDate: Date;

  constructor() {
    var d = new Date();
    this.testDate = new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes());
  }

  test() {
    console.log('test');
  }

}

See adjusted plnkr code .请参阅调整后的plnkr 代码

This is definitely a bug.这绝对是一个错误。 Even when I supply a "null" value to the bound property, the widget still fires the valueChanged() event.即使我为绑定属性提供“空”值,小部件仍会触发 valueChanged() 事件。

If the input is null there is nothing to change.如果输入为空,则无需更改。 If the input is "initialized" there is nothing changed.如果输入被“初始化”,则没有任何改变。

Definitely a bug.绝对是个bug。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM