I used datalist to search the value which I entered in input field and filtered. I need to send selected options id to the controller function.
<input list="browsers" type="text" id="searchtextbox" class="form-control" placeholder="Search" ng-model="searchText">
<datalist id="browsers">
<option ng-repeat="data in enroldata | filter: searchText" id="{{data.USERID}}" id="{{data.USERID}}" value="{{data.FIRSTNAME}} {{data.LASTNAME}}">{{data.FIRSTNAME}} {{data.LASTNAME}}</option>
</datalist>
<input type="button" class="btn btn-primary btn-flat" ng-click="enrol({{data.USERID}})" value="Send" />
In controller
$scope.enrol = function (USERID) {
debugger;
var value = $scope.USERID;
var val = $('#searchtextbox').val();
var states = $('#browsers');
var endVal = $(states).find('option[value="' + val + '"]');
//depending on your logic, if endVal is empty it means the value wasn't found in the datalist, you can take some action here
return endVal.text();
var USERID1 = $scope.searchText;
//var value = $('#searchText').val();
//alert($('#browsers [value="' + value + '"]').data('value'));
//var x = $('#searchtextbox').val();
//var z = $('#browsers');
//var val = $(z).find('option[value="' + x + '"]');
//var endval = val.attr('id');
//alert(endval);
debugger;
var dat = {
"courseid": localStorage.getItem("courseid")
, "USERID": USERID
}
}
I need search by username and pass the USERID by fucntion or with id binding.... I tried to call it by id and passed with function its return undefined.
ng-repeat="data in enroldata | filter: searchText"
data is only accessible from the inside of ng-repeat
I think You can simply call enrol() on click (ng-click="enrol()"
) and get data inside the controller from the $scope.enrolData