0

I am new to AngularJS, just making a small filter data table. I have a text box, on ng-keydown I am calling a function, in this function I want the value of that textbox.

How can I get it. My code:

HTML:

<body ng-controller="ApplicantsListCtrl">
<input type="text" class="form-control" name="company" ng-model="c" ng-keydown="filter()"></p>
</body>

JS

var app = angular.module('MyApp',[]);

    app.controller('ApplicantsListCtrl',['$scope',function($scope){

        $scope.filter = function(){
            console.log($scope.c);
        };
    }]);

I am getting undefined in my log.

Is this correct way to do it?

1

3 Answers 3

3
<input type="text" data-ng-change="key(data)" data-ng-model="data"/>

$scope.key = function (data) {
            console.log(data);
        };

This works.

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

1 Comment

Glad this helped you
2

Rather than keydown, use $watch. See the plunker here

Comments

1

I would use ng-change="filter(c)"

1 Comment

I prefer this option over the watch

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.