Is there a way to avoid repeating the if condition in multiple controllers? How can I simplify this process?
MainController.js :
$scope.responseData.forEach(function(card) {
switch (card.Category) {
case 'Apple':
console.log("Apple");
break;
case 'Google':
console.log("Google");
break;
case 'Microsoft':
console.log("Microsoft");
break;
case 'Amazon':
console.log("Amazon");
break;
}
});
FirstController.js :
$scope.responseData.forEach(function(card) {
switch (card.Category) {
case 'Apple':
console.log("Apple");
break;
case 'Google':
console.log("Google");
break;
case 'Microsoft':
console.log("Microsoft");
break;
case 'Amazon':
console.log("Amazon");
break;
}
});
SecondController.js :
$scope.responseData.forEach(function(card) {
switch (card.Category) {
case 'Apple':
console.log("Apple");
break;
case 'Google':
console.log("Google");
break;
case 'Microsoft':
console.log("Microsoft");
break;
case 'Amazon':
console.log("Amazon");
break;
}
});
How can I centralize this condition and reuse it across multiple controllers?