Angular 在数据绑定之前触发模糊
我有一个角度,提供了一个模糊函数的日期。在Chrome(v62)中,它可以正常工作,但似乎不能与Firefox(57)一起工作 //htmlAngular 在数据绑定之前触发模糊,angular,firefox,Angular,Firefox,我有一个角度,提供了一个模糊函数的日期。在Chrome(v62)中,它可以正常工作,但似乎不能与Firefox(57)一起工作 //html <input #expirationDate type="date" max="2999-12-31" class="form-control" name="ChargeExpirationDate" [ngModel]="charge.ExpirationDate" (blur)="editCharge(charge, 'ExpirationDa
<input #expirationDate type="date" max="2999-12-31" class="form-control" name="ChargeExpirationDate" [ngModel]="charge.ExpirationDate" (blur)="editCharge(charge, 'ExpirationDate', expirationDate.value)"/>
如果你输入一个日期,输入的内容就会失去焦点
- 在Chrome中:函数被调用,
包含一个日期字符串newValue
- 在Firefox中:函数启动,但
设置为newValue
。更奇怪的是,“”
将实际包含字符串,但仅在console.log(charge)的结果
函数完成后观察editCharge
有没有办法在Firefox中的模糊事件发生之前正确设置
newValue
?我不想使用ngModelChange
,因为当我们试图用它在Chrome中输入日期时,我们注意到了一些不寻常的行为 与注释中一样,您应该使用focusout
事件,而不是blur
<input #expirationDate type="date"
class="form-control"
max="2999-12-31"
name="ChargeExpirationDate"
[ngModel]="charge.ExpirationDate"
(focusout)="editCharge(charge, 'ExpirationDate', expirationDate.value)"/>
尝试focusout
似乎已经解决的事件谢谢!这样做会有什么后果吗?我不完全清楚那是什么意思。哪一部分不清楚?请不要介意。我有点担心这个评论:“……这个事件和模糊之间的主要区别是后者不冒泡。”但我查了一下,我认为它不会对我的应用程序产生负面影响。所以你的问题解决了,对吗?
<input #expirationDate type="date"
class="form-control"
max="2999-12-31"
name="ChargeExpirationDate"
[ngModel]="charge.ExpirationDate"
(focusout)="editCharge(charge, 'ExpirationDate', expirationDate.value)"/>