0

So I've set up a factory like so using $resource:

'use strict';

angular.module('hscApp')


  /* ----------------------
  Test- Using channel_id
  ------------------------ */

  .factory('Data', function($resource){

  return {
    retrieve: function() {

          params = {
            status: 'upcoming',
            followed: 1,
            reason: 1,
            views: 1,
            per_page: 2,
            channel_id: 2165604
          };

      return $resource('/api/v1/channel_listings.json', params);
    }
  };
})

The format of the API is something what I have listed below:

api/v1/channel_listings.json?status=upcoming&followed=1&reason=1&views=1&per_page=2&channel_id=2165604

I "think" I have this set up correctly, but I'm not really sure. The goal is to have dynamic parameters to pass into this factory (namely the channel id). I set up my controller like:

'use strict';

angular.module('hscApp')
  /* main controller */
  .controller('MainCtrl', function ($scope) {
    $scope.$on('$viewContentLoaded', angularOnLoad);
  })

  .controller('TestCtrl', function(Data){
    $scope.Data = Data.retrieve({
      status: 'upcoming',
      followed: 1,
      reason: 1,
      views: 1,
      per_page: 2,
      channel_id: 216560
    });
    Data.get(function(data){
      $scope.upcomingEvents = data;
    });    
  });

Then I'm trying to display a field from the JSON by doing {{ event.name }} but I'm getting errors saying Data is not defined. Am I doing something wrong here?

Mr. BigglesWorth
  • 1,530
  • 3
  • 18
  • 33
  • first of all, you have to inject `$scope` in TestCtrl... and I think the problem is with the line `Data.get(function(data){`, it should be `$scope.Data.get` if you want to do what I think you want to do – doodeec Mar 21 '14 at 07:56
  • Sorry, I didn't have my latest code up there with scope injected. Here is the updated Fiddle. http://jsfiddle.net/poopertropper/29zQv/4/ It doesn't seem to return anything at all so I'm not sure if I'm using params correctly. – Mr. BigglesWorth Mar 21 '14 at 17:24

0 Answers0