结合两个输入相同的模型模型、两个

2023-09-14 23:08:38 作者:一别两宽,各生欢喜

在本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);
});