title: Retrieving Linked Entry Fields in Contentful with Angular (Ionic)
body: <p>I'm new to Contentful and Angular (working in Ionic) and having some difficulty sorting out how to properly retrieve field data from a Contentful entry's related content (aka "Link").</p>
  
  <p>As things stand, I can list my entries according to the 'Terms' factory, and can move to an individual entry state in which I can list the linked content by--obvious as you see here--just the id.</p>
  
  <p>I feel like this can be resolved in the/a factory, but just not quite sure how to proceed. Nothing that I've tried has so far worked. And, if it's the case that I'm going about this all wrong, I'm happy to be told so.</p>
  
  <p>Many thanks in advance.</p>
  
  <p><strong>services.js</strong></p>
  
  <pre><code>angular.module('app.services', ['ngResource'])
  
  .factory('Terms', function ($resource, $log) {
  
    var apiGetEntries = 'https://cdn.contentful.com/spaces/SPACE_ID/entries?access_token=MY_ACCESS_TOKEN';
  
    var terms = $resource(apiGetEntries, null, {
  
      query: {
        method: 'GET',
        isArray: true,
        transformResponse: function(data, headers) {
          var entriesRaw = angular.fromJson(data);
          var entries = [];
          angular.forEach(entriesRaw.items, function(entry) {
            entries.push(entry);
          });
          console.log(entries);
          return entries;
        }
      }
  
    });
  
    return terms;
  
  })
  </code></pre>
  
  <p><strong>controllers.js</strong></p>
  
  <pre><code>angular.module('app.controllers', [])
  
  .controller('getTerms', function($scope, Terms) {
  
    $scope.terms = Terms.query();
  
  })
  
  .controller('getTermDetail', function($scope, $http, $stateParams) {
  
    var apiBasePath = 'https://cdn.contentful.com/spaces/SPACE_ID/entries/';
    var accessToken = 'MY_ACCESS_TOKEN';
    var termId      = $stateParams.termId;
  
    $http({
      url: apiBasePath + termId, 
      method: "GET",
      params: { access_token: accessToken }
    }).success(function(data, status, headers, config) {
        $scope.term = data;
        if(typeof $scope.term.fields.relatedTo != 'undefined') {
          $scope.relatedTerms = $scope.term.fields.relatedTo
        }
      }).error(function(data, status, headers, config) {
        console.log(data);
      })
  
  });
  </code></pre>
  
  <p><strong>templates/term-definition.html</strong></p>
  
  <pre><code>&lt;ion-view view-title="Definition"&gt;
    &lt;ion-content class="padding"&gt;
      &lt;h2&gt;{{ term.fields.term }}&lt;/h2&gt;
      &lt;p&gt;
        {{ term.fields.definition }}
      &lt;/p&gt;
      &lt;ion-list&gt;
        &lt;ion-item class="" ng-repeat="relatedTerm in relatedTerms" type="item-text-wrap" href="#/tab/terms/{{ relatedTerm.sys.id }}"&gt;
          {{ relatedTerm.sys.id }}
        &lt;/ion-item&gt;
      &lt;/ion-list&gt;
    &lt;/ion-content&gt;
  &lt;/ion-view&gt;
  </code></pre>