简体   繁体   English

鼠标结束时输入字段更新

[英]Input fields updates when mouse is over

I made an angular 2 model-driven form with nested fields. 我用嵌套字段制作了一个带角度的2模型驱动形式。 One of this fields is a numeric field and I am using a jquery plugin to make numeric formatted. 其中一个字段是数字字段,我使用jquery插件进行数字格式化。 I created a directive to init this plugin when a new line of input are added, but when I add a new line, a total must be divided to all lines, it's a quantity. 当添加新的输入行时,我创建了一个初始化此插件的指令,但是当我添加新行时,必须将总计划分为所有行,这是一个数量。 This division I made in a function in my model to update the fields in the formGroup. 我在模型中的一个函数中进行了这个划分,以更新formGroup中的字段。

My problem is, the view shows the new value for each line, but, the plugin is formatting this field and the browser only shows the field formatted when I put the mouse cursor over. 我的问题是,视图显示每行的新值,但是,插件正在格式化此字段,浏览器仅显示当我将鼠标光标放在上面时格式化的字段。 It seems that angular is not updating the view as it should. 似乎angular不会更新视图。

Here are some images about whats happening: 以下是一些关于发生什么的图片:

First when the layer appears, the first field in the top is not showing formatted, but it's. 首先,当图层出现时,顶部的第一个字段未显示格式化,但它是。 图片1

Here is how it shows after moving the mouse over: 以下是移动鼠标后的显示方式: 图片2

I added some lines, see how they are shown: 我添加了一些行,看看它们是如何显示的: 图片3

And after moving the mouse over: 移动鼠标后: 图片4

Ps: Don't tell me "you should not use jquery with angular blah blah blah...". Ps:不要告诉我“你不应该使用jquery with angular blah blah blah blah ......”。 I know this, but I needed to use it. 我知道这一点,但我需要使用它。

My best guess is the changes you're making is made outside Angular hence its change detection engine is not aware of the changes. 我最好的猜测是你所做的改变是在Angular之外进行的,因此它的变化检测引擎并不知道这些变化。 One simple way to force this is using setTimeout 强制执行此操作的一种简单方法是使用setTimeout

setTimeout(() => {
  // Code that modify model values go here
})

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

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