Here's a snippet of code I've been using that involves the use of eval
. I opted for this approach as it seemed like the most straightforward way to trigger various factory functions, each responsible for different web service calls.
I'm aware that using `eval` is deemed unsafe and not the most ideal method. However, at present, I'm struggling to come up with an alternative solution that aligns with my requirements.
Is there a more secure or effective way to achieve the same functionality?
vm.saveRecord = function() {
var service = '';
if(vm.valueTrue) {
service = vm.otherValue ? 'function1' : 'function2';
} else {
service = vm.otherValue ? 'function3' : 'function4';
}
eval(service).callEndPoint(param1, param2).then(
function successCallback(response) {
if(response) {
// Handle successful response
}
}, function errorCallback(response) {
// Handle error
}
)
};