1

I want to bind Typeahead enter event in angularjs. I have always used jQuery as follows:

this.$("input#search-box").bind('typeahead:enterKeyed', function (e, data) {
    //to do stuff
}

I want write code similar to this in angularjs.I am using ui-bootstrap-typeahead typeahead is working fine but need to bind the enter event to load other functions

I have tried this:

angular.module('genericDirectives', []).directive('ngEnter', function () {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            element.bind("typeahead:enterKeyed", function (event) {
                    console.log("Enter");
                    scope.$apply(function () {
                        scope.$eval(attrs.ngEnter);
                    });
                    event.preventDefault();
            });
        }
    };
});

HTML

<input type="text" data-ng-model="selectedSongs" ng-enter="reloadData(selectedSongs)" typeahead="songs for songs in getSongs($viewValue)" class="form-control" />

P.S.: I am new to angualrjs

3
  • 1
    Your best bet is probably ui.bootstrap.typeahead Commented May 20, 2014 at 12:18
  • there is no bind event to it Commented May 20, 2014 at 13:11
  • tried that but not working Commented May 20, 2014 at 13:14

1 Answer 1

1

You could try using: typeahead-on-select($item, $model, $label).

Example:

<input id="search-box" type="text" ng-model="selectedData" typeahead-on-select="doSomething(selectedData)" />

Make sure you have it in $scope:

$scope.doSomething = function (value) {
    // do something...
}
Sign up to request clarification or add additional context in comments.

1 Comment

What a beaut. Good suggestion!

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.