0

I am making my first steps with angular, I just want to simply clear the content of a input text when I click on it. this is the markup

<div ng-app="myApp" ng-controller="myCtrl"> First Name: <input id="123" type="text" ng-click="unsetValue($e)" ng-model="firstName"><br> Last Name: <input id="456" type="text" ng-click="unsetValue($e)" ng-model="lastName"><br> <br> Full Name: {{firstName + " " + lastName}} </div> 

this is the js in an external file

var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.firstName= "John"; $scope.lastName= "Doe"; $scope.unsetValue = function($event) { console.log($event); } 

when I click the control, $event is undefined, any idea why?

thanks M

1
  • Note the correct syntax in the other post $event instead of $e and the answer on the linked post shows the directive source which shows the named $event Commented Aug 30, 2017 at 15:52

2 Answers 2

0

You have to call ng-click in this way: ng-click="unsetValue($event)"

Update

Later in the function you can name parameter as you like for example:

$scope.unsetValue = function(e) { console.log(e); } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I thought that was just a name for a variable, not that I had to use a specific name. I will accept this in 7 mins
0

The name of the variable passed in is $event, not $e

so you need to use ng-click like this

ng-click="unsetValue($event)" 

the rest of your code is fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.