Pull results from services to collection and display on list


Hey Guys,

I’m new to Ionic and i’m trying to convert the data from a local array on the demo app to using data from a json feed.

If i put the code into the controller directly i can pull items and display in the list. If i add the code into the services file and link to the function in the controller it doesn’t seem to return the data to the list and display.

Here is both my services and controller:


angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope) {

.controller('PlaylistsCtrl', function($scope, MenuFeed) {

	$scope.items = [];
  	$scope.items = MenuFeed;


  	return $scope.items; 

.controller('PlaylistDetailCtrl', function($scope, $stateParams) {
	$scope.items = Friends.get($stateParams.playlistId);


angular.module('starter.services', [])

.factory('MenuFeed', function($http) {

  var myHeader = {headers: {
            'Application-id': 'HIDDEN',
            'secret-key': 'HIDDEN'
  $http.get('https://api.backendless.com/v1/data/menu', myHeader).success(function (data) {


      return data.data;



I’m not sure what’s broken but any help would be great. I tried to put it on codepen but i don’t know how to put the services file as a seperate file without paying.



This is more Angular specific.

//From you're factory:
.factory('MenuFeed', function($http) {
  return {
    getDataFunc: function() {
      // Set header

      return $http.get('https://api.backendless.com/v1/data/menu', myHeader).success(function (data) {
        return data.data;

//And call it from you're controller
$scope.items = MenuFeed.getData();


Thank you for the reply, it now pulls the function through and displays the data on the console.

Sadly though, it still doesn’t display it on the list. Any ideas? :frowning:


Ok in the controller, replace $scope.items = MenuFeed.getData();

MenuFeed.getData().then(function(data) {
  $scope.items = data;


That’s got it :slight_smile: Thank you very very much!

Now just to figure out how to view the data on the detail screen with the id :smiley: