I am new to angular and am trying to do something pretty simple in vanilla javascript but am unable to find out how to do it properly in angular!
I want to set up a general function to clear an input text field:
I have this html:
<input type="text" ng-model="css" ng-focus="clearInput('css')"/>
(got the ng-focus thing here: https://groups.google.com/forum/?fromgroups=#!topic/angular/A5Lyx8m3S4M it works well!)
and this function in my controller
$scope.clearInput = function (val) {
$scope.val = "";
};
Clearly this would work if I would use $scope.css, but I want to be able use the function for other input fields as well. There's got to be a nice angular way of doing this!!
Thanks!
I think it's easier just to clear it using "css=''".
For example, the following clears the input each time you click on it:
<input type="text" ng-model="css" ng-click="css=''"></input>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With