简体   繁体   English

清除另一个输入时清除输入类型的文本

[英]clear input type text when another input is cleared

so I have two input texts and when I clear one of them, I want another one to be automatically cleared too. 所以我有两个输入文本,当我清除其中一个时,我也希望自动清除另一个。

Is there any nice angular way to do this inside template? 在模板内部有什么不错的角度方法吗?

<input type="text" ng-model="one" class="form-control">
<input type="text" ng-model="two" class="form-control">

these are the fields, when I clear first one, I want second to be cleared too 这些是字段,当我清除第一个字段时,我也想清除第二个字段

Watch on first textbox for change, when it gets cleared, clear another also. 在第一个文本框上查看更改,清除后再清除另一个。

Here is what you want. 这就是你想要的。

$scope.$watch("one",function(newVal){
  if(newVal=="")
    $scope.two="";
})

If u ve a form u can use the $setPristine(); 如果您有表格,可以使用$ setPristine();。 method 方法

example: 例:

<button ng-click="mymagicform.$setPristine();">Submit</button>

doc link https://docs.angularjs.org/api/ng/type/form.FormController doc链接https://docs.angularjs.org/api/ng/type/form.FormController

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

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