繁体   English   中英

匹配两个文本框的值

[英]matching values of two textboxes

我有两个具有不同ng-models文本框。 单击按钮后,将使用$http.get请求填充它们。

可以说:

<input type="text" ng-model="name.title" />
<input type="text" ng-model="name.surname" />

从我的JSON数据中可以很好地填充这些内容。

我的name.title的值有时可能类似于“ abc(123)”。 如果用户对此进行编辑,则希望name.surname成为()中的一部分。 如果用户删除“ abc(123)”并仅键入123,则123应该反映在name.surname

我已经尝试了使用ng-blurng-change各种组合,但是到目前为止,对我来说都没有用。

它只是一个两个文本框,因此编写新指令毫无意义。

我该怎么做呢?

任何帮助将不胜感激。 :)

我假设您使用的是1.x角度。

您可以监视名字。 像你里面的东西

 $scope.$watch('[name.title, name.surname]', function(newValue, prevValue) { if (newValue === prevValue) { return; } //Here you put your logic and update the models. }); 

暂无
暂无

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

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