Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keypress in Angular-UI

I am running into some problems using the keypress as follows-

<div ng-controller="GBNController">
...
<input id="search-field" type="text" placeholder="JSON Query" ng-model="queryText" ui-keypress="{enter: foo()}"/>
...
</div>

and my javascript has -

var AngApp = angular.module('gbn', ['ui']);
var GBNController = function($scope) {
    $scope.queryText = '';
    $scope.foo = function() {
        alert('test');
    }
};

Now this function foo is called only when the document is loaded and then after that, the return keypress event in the text field is never handled.

I am using the current head of the master branch.

Am I doing something wrong here, or is this broken??

like image 258
ssb Avatar asked Jun 14 '26 05:06

ssb


1 Answers

You need to put foo() in quotes.

<input ui-keypress="{enter: 'foo()'}">

like image 73
Andrew Joslin Avatar answered Jun 16 '26 20:06

Andrew Joslin