如何使用 angularJS 在单击按钮时清除文本输入?
X 是一个单独的链接,我想在其上触发一个函数。
HTML
<input type="text" class="form-control" data-ng-model="searchAll">
<a class="clear" data-ng-click="clearSearch()">X</a>
最佳答案
只需清除点击事件中的范围模型值,它就可以为您解决问题。
<input type="text" ng-model="searchAll" />
<a class="clear" ng-click="searchAll = null">
<span class="glyphicon glyphicon-remove"></span>
</a>
或者如果您保留 Controller 的 $scope
函数并从那里清除它。确保您已正确设置 Controller 。
$scope.clearSearch = function() {
$scope.searchAll = null;
}
关于javascript - 使用 AngularJS 单击时清除文本输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21708689/