Angularjs - using Typeahead should show 2 values
I use typeahead
, I like to get dynamic data, more useful
<input required type="text" ng-model="student"
placeholder="{{'STUDENT_ID_FIRST_NAME_LAST_NAME' | translate}}"
typeahead="student as student.lastName for student in getStudents($viewValue)"
typeahead-loading="loading" class="form-control">
My javascript code for fetching students is -
$scope.getStudents = function(val) {
var queryCriteria = {
q: JSON.stringify([{
field: 'lastName',
op: APP_CONSTANTS.SEARCH_OPERATORS.CONTAINS,
value: val
}, {
field: 'firstName',
op: APP_CONSTANTS.SEARCH_OPERATORS.CONTAINS,
value: val
}, {
field: 'userId',
op: APP_CONSTANTS.SEARCH_OPERATORS.CONTAINS,
value: val
}]),
joinCondition: APP_CONSTANTS.JOIN_CONDITIONS.OR,
order: APP_CONSTANTS.SORTING_ORDER.DESCENDING,
limit: 10,
orderBy: 'createdAt',
page: 1
}
return Students.query(queryCriteria).then(function(response) {
return response.data;
});
};
I want to show the concatenation of student.lastName
and student.firstName
. Please suggest how to do this.
+3
user4874420
source
to share
1 answer
You can just use string concatenation student.lastName + ' ' + student.firstName
<input required type="text" ng-model="student"
placeholder="{{'STUDENT_ID_FIRST_NAME_LAST_NAME' | translate}}"
typeahead="student as student.lastName+' '+student.firstName for student in getStudents($viewValue)"
typeahead-loading="loading" class="form-control">
+2
source to share