0

I display data from a json. I want replace values from an other (for translation). It's like :

    <li ng-repeat="childrens in data.children track by $index">
         <a>{{childrens.type}}</a>
    </li>

In 'type' I can have "QUOTE", "BILL" or "DEPOSIT"... And I want replace this value with the translation.

But I'm beginner in angular, and i work on json for the first time as well, what's the better way to do this ?

I tried to use the fonction replace() in my controller but that doesnt work :

   if($scope.children.type =='QUOTE'){
       $scope.children.type = $scope.children.type.replace('Facture');
   }

Thanks for your help guys :)

2
  • for translate better use angular translate Commented Dec 26, 2016 at 14:19
  • I need translation juste for 3 words so maybe it's not enough for use angular translate ? ^^ Commented Dec 27, 2016 at 9:04

1 Answer 1

1

You can do this:

<li ng-repeat="childrens in data.children track by $index">
   <a>{{mapObject[childrens.type].text}}</a>
</li>

In Controller you can use javascript map

$scope.mapObject = {
  "QUOTE":{
    "text":"Facture"
   }
}
Sign up to request clarification or add additional context in comments.

Comments

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.