Reputation: 9247
I have this in controller :
$scope.SearchOnEnter = function (event) {
var element = angular.element(event.target);
if (event.keyCode === 13) {
_search(element.val());
}
}
In html i have this:
<input type="search" data-ng-model="searchText" data-ng-model-options="{ debounce: 1000 }" placeholder="@Translator.Translate("SEARCH_OFFER")" data-ng-keydown="checkKeyDown($event);SearchPOnEnter($event)" data-ng-change="search()" data-ng-enter="SearchOnEnter(searchText)" />
But in console im geting error:
Unable to get property 'target' of undefined or null reference
Upvotes: 1
Views: 1535
Reputation: 9550
Check this demo: JSFiddle.
It simply works as expected. Your JSFiddle doesn't work because you do not import AngularJS correctly. Also need to add ng-app="myApp"
:
<div ng-app="myApp" ng-controller="MyCtrl">
Upvotes: 1
Reputation: 802
You're passing searchText to the function:
data-ng-enter="SearchOnEnter(searchText)"
but in the function expect it to be an event.
I guess you meant it to be
data-ng-enter="SearchOnEnter($event)"
Upvotes: 0