结合两个输入相同的模型

编程入门 行业动态 更新时间:2024-10-27 12:39:24
本文介绍了结合两个输入相同的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

结合两个输入相同的模型

本文发布于:2023-10-26 17:10:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530785.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!