I store leads statutes in my database. The values could be 1,2,3 or 4.
Actually I return a human readable using the ngResource get:
Client.get({ id: $stateParams.clientId }, function(data) {
$scope.client = data;
// Start of numeric values to status
for(var i=0;i<data.leads.length;i++){
if(data.leads[i].statut===1){
data.leads[i].statutMessage = 'À contacter';
}
else if(data.leads[i].statut===2){
data.leads[i].statutMessage = 'En cours';
}
else if(data.leads[i].statut===3){
data.leads[i].statutMessage = 'Obtenu';
}
else if(data.leads[i].statut===4){
data.leads[i].statutMessage = 'Non obtenu';
}
}
});
I would like to extract this logic to Client service so that each leads "statut" (1,2,3,4) is converted to real statutes ('À contacter', 'En cours', 'Obtenu', 'Non obtenu').
Can I use this technique (directive)
If a directive is not the right way in this case, how should I do this?