Angularjs : make input = null when ng-hide = true

Angularjs : make input = null when ng-hide = true

本文关键字:when ng-hide true null Angularjs make input      更新时间:2023-09-26

你好,我想让输入文本为空当它变成隐藏(ng-hide="true")

我需要多个隐藏输入的动态解决方案

因此,如果有人选择了Yes,则输入子数如果选中了No,则需要child count变为空

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<form ng-app>
<select ng-model="has_child">
<option value="1">Yes</option> 
<option value="2">No</option>
</select>
<input type="text" ng-model="childcount" ng-hide="has_child == 2"/>
<input type="text" ng-model="mailcount" ng-hide="has_child == 2"/>
<input type="text" ng-model="femailcount" ng-hide="has_child == 2"/>
</form>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<form ng-app>
<select ng-model="has_child" ng-change='has_child == 2 ? childcount=null: ""'>
<option value="1">Yes</option> 
<option value="2">No</option>
</select>
<input type="text" ng-model="childcount" ng-hide="has_child == 2"/>
</form>

在select中使用ng-change

<select ng-model="has_child" ng-change="option()">

并在控制器

中添加此函数
$scope.option=function(){
    if($scope.has_child==2){
    $scope.childcount='';
    }
    console.log($scope.childcount);
}

谢谢