结合两个输入相同的模型 [英] Binding two inputs to the same model

查看:149
本文介绍了结合两个输入相同的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本plunker 证明,我想有一个<输入类型=数字/> <输入类型=范围/>这两个更新同一 $范围变量,以及对方。

As demonstrated in this plunker, I'd like to have an <input type="number"/> <input type="range"/> which both update the same $scope variable, as well as each other.

现在,当我更新一个输入$范围变量发生变化,但其他范围的值被消隐。我只需要绑定一条数据-NG-模型和其他使用数据NG-变化?是否有一个清晰的解决方案?

Right now, when I update one input the $scope variable is changed, but the value of the other scope is blanked. Do I just need to bind one with data-ng-model and use data-ng-change on the other? Is there a cleaner solution?

推荐答案

不知道这是为什么,但是当您更改类型=数字为type =文本它的工作原理。

Not sure why this is, but when you change the type="number" to type="text" it works.

我发现这个解决方法输入类型=数字,但似乎有点哈克:

I found this workaround for input type="number" but seems a bit hacky:

$scope.$watch('MyNumber',function(number) {
  $scope.MyNumber = Number(number);
});

这篇关于结合两个输入相同的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆