1

How do I map the example in the json output to a string based on the position? It's rather difficult to explain, but I have included my code and further details below:

JSON output

[
    {
        "phrase": "Training {{group}} to develop their {{attribute}} by ensuring they are comfortable with {{factor}}",
        "example": "the team",
        "position": 0
    },
    {
        "phrase": "Training {{group}} to develop their {{attribute}} by ensuring they are comfortable with {{factor}}",
        "example": "match skills",
        "position": 1
    },
    {
        "phrase": "Training {{group}} to develop their {{attribute}} by ensuring they are comfortable with {{factor}}",
        "example": "defence techniques",
        "position": 2
    }
]

controller.js

PhraseService.getPhraseExample($scope.phraseId).then(function(dataResponse) {
  $scope.phraseExampleList = dataResponse.data;
})

services.js

function PhraseService($http) {

  this.getPhraseExample = function(phraseId) {

    return $http({
      method: 'GET',
      url: server + '/api/phrase-example/' + phraseId,
    });

  }

}

phrase-detail.html

<div class="item item-text-wrap">
    <span ng-repeat="e in phraseExampleList">{{ e }}</span>
</div>

Current output

enter image description here

Desired output

enter image description here

methuselah
  • 12,766
  • 47
  • 165
  • 315

1 Answers1

1

You want something as described in https://stackoverflow.com/a/18234317/3856625 Seems that StackOverflow has the same method you need :)

So you would map over the entries you have and just use it to replace the needed.

Community
  • 1
  • 1
gor181
  • 1,988
  • 1
  • 14
  • 12