angularjs - Retrieving Linked Entry Fields in Contentful with Angular (Ionic) -


i'm new contentful , angular (working in ionic) , having difficulty sorting out how retrieve field data contentful entry's related content (aka "link").

as things stand, can list entries according 'terms' factory, , can move individual entry state in can list linked content by--obvious see here--just id.

i feel can resolved in the/a factory, not quite sure how proceed. nothing i've tried has far worked. and, if it's case i'm going wrong, i'm happy told so.

many in advance.

services.js

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;  }) 

controllers.js

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);     })  }); 

templates/term-definition.html

<ion-view view-title="definition">   <ion-content class="padding">     <h2>{{ term.fields.term }}</h2>     <p>       {{ term.fields.definition }}     </p>     <ion-list>       <ion-item class="" ng-repeat="relatedterm in relatedterms" type="item-text-wrap" href="#/tab/terms/{{ relatedterm.sys.id }}">         {{ relatedterm.sys.id }}       </ion-item>     </ion-list>   </ion-content> </ion-view> 

you don't need of hand unless have specific use case. can use official contentful js sdk or third party angular js contentful integration. both of them deal link resolution automatically. can see more info links here https://www.contentful.com/developers/docs/concepts/links/ , here https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links

hope helps :)


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -