This is my object array and it is bound to a dropdownlist:
$scope.dropdownOptions = [{value: "0", name: 'No'}, {value: "1", name: 'Yes'}];
I want to return the corresponding "Name" depending on the selected "Value" in the dropdown through the following function. Right now I have hardcoded the return values.
$scope.getDropdownDisplayValue = function(_key){
if(_key == "1")
return "Yes";
else if(_key == "0")
return "No";
else
return "n/a";
};
The problem is, if I modify the Names property of objects in that array I will have to come and change the return values of the above function as well. To Avoid that, I want to serach the object array and return the corresponding value. For example:
$scope.getDropdownDisplayValue = function(_key){
if(_key == "1")
return <get object.name where object.value == _key from dropdownOptions array>
else if(_key == "0")
return <get object.name where object.value == _key from dropdownOptions array>
else
return "n/a";
};
I can write a custom function for that, but want to whether I can use something already available in AngularJS or JavaScript. Thanks in advance.