keydown上的Angular JS获得了价值

时间:2014-01-23 14:27:42

标签: angularjs textbox

我是AngularJS的新手,只是制作一个小的过滤数据表。我有一个文本框,在ng-keydown我正在调用一个函数,在这个函数中我想要该文本框的值。

我怎样才能得到它。我的代码:

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);
        };
    }]);

我的日志中未定义。

这是正确的方法吗?

3 个答案:

答案 0 :(得分:2)

而不是keydown,使用$ watch。请参阅plunker here

答案 1 :(得分:2)

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

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

这很有效。

答案 2 :(得分:1)

我会使用ng-change="filter(c)"

相关问题