3

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!

Heading

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliantly simple. Thanks Andy! Another light bulb just lit up!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.