我是 Angular 的新手,我想在普通的 javascript 中做一些非常简单的事情,但我无法找到如何在 Angular 中正确地做到这一点!
我想设置一个通用函数来清除输入文本字段:
我有这个 html:
<input type="text" ng-model="css" ng-focus="clearInput('css')"/>
(这里有 ng-focus 的东西: https://groups.google.com/forum/?fromgroups=#!topic/angular/A5Lyx8m3S4M 它运作良好!)
这个函数在我的 Controller 中
$scope.clearInput = function (val) {
$scope.val = "";
};
显然,如果我使用 $scope.css,这会起作用,但我也希望能够将该函数用于其他输入字段。必须有一个很好的角度方法来做到这一点!!
谢谢!
标题
最佳答案
我认为使用 "css=''"
清除它更容易。
例如,以下每次单击时都会清除输入:
<input type="text" ng-model="css" ng-click="css=''"></input>
关于angularjs-scope - Angularjs - 动态设置 $scope 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16251256/