I have a dropdown menu that is being formatted using filters to display the text in a certain way. I need to send the selected item's ID value to the controller instead of just the name:
<select
ng-model="my_field"
ng-options="q.name as (q.name | filter1 | filter2) for q in my_fields track by q.id"
ng-change="controllerMethod(my_field)"
required>
</select>
// Controller
function controllerMethod(selected_field){
console.log(selected_field);
}
$scope.controllerMethod = controllerMethod;
// Filters
angular.module('app')
.filter('filter1', function(){
return function(str_value) {
return str_value ? str_value.split('_').join(' ') : "";
}
})
.filter('filter2', function(){
return function(str_value) {
return (!!str_value) ? str_value.charAt(0).toUpperCase() + str_value.substr(1).toLowerCase() : '';
}
})
Previously, without the filters, all object data was being sent to the controller. Now, only the name is being passed. How can I pass the ID of the selected object instead?
Thank you!