0

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?

1 Answer 1

1

Well when you need to display the "statutes" you could modelize it this way in your controller:

$scope.leadMessages = {
  1: 'À contacter',
  2: 'En cours',
  3: ..etc
}

And in your HTML:

<div ng-repeat="lead in data.leads">{{leadMessages[lead.statut]}}</div>

Bon courage :-)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you/ Merci! Je vais utiliser cette technique.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.