Kiloumap
Kiloumap

Reputation: 2243

Replace values from json

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 :)

Upvotes: 0

Views: 95

Answers (1)

Bhuneshwer
Bhuneshwer

Reputation: 587

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"
   }
}

Upvotes: 1

Related Questions