0

how I do :

<input ng-keyup="foo($event)">

$scope.foo = function (event) {
  var v = event.srcElement.value;
}

how I want to do :

<input ng-keyup="foo(this.value);">

$scope.foo = function (v) {
  var v = v;
}

this doesn't work. this doesn't reference to the input element.

2 Answers 2

1

For all the ng- events(or other directives) types this means the scope with which the DOM is compiled.

Bind the input's value to a model and use in your event handler.

<input ng-model="myModel" ng-keyup="foo()">

In Controller

$scope.foo = function () {
    //use $scope.myModel
}

If you don't want to bind the input to a model, the solution which you are using currently is fine.

Sign up to request clarification or add additional context in comments.

Comments

0

You should bind the value of the input to the $scope using ng-model and either pass that value in as a parameter to foo or you can reference it directly in the definition of $scope.foo.

3 Comments

thanks for your support but I am not trying to bind anything.
However, consider the update of my post, the foo function is in the scope.
If you share more code it can be clearer what you are trying to do, but in general scopes are designed to serve as the single source of your model.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.