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
ui.bootstrap.typeahead