0

I have a route as below:

var entryShow = {
  name: 'entry.show',
  url: '/:entry_id',
  views: {
    '@':{
      templateUrl: TEMPLATES.entry_show,
      controller : 'EntryShowController',
      resolve: {
        entryData: ['$stateParams', 'Entry', function($stateParams, Entry){
          return Entry.getEntry($stateParams.entry_id);
        }],
        entryHistory: ['$stateParams','Entry',function($stateParams,Entry){
          return Entry.getHistory($stateParams.entry_id);
        }]
      }
    }
  }
};

In my controller I have added the two resolves as follows :

App.controller('EntryShowController',['$scope','$state','entryData', 'Entry',
function($scope, $state, entryData, entryHistory, Entry) {
    ...
    $scope.entry = entryData.data.entry;
    console.log('Entry History');
    console.log(entryData);
    console.log(entryHistory);
    $scope.entry.history = entryHistory.data;
    ...
}]);

Here in console.log I get the correct result for entryData but for entryHistory I get the entryService object instead of the result. Also when I swapped the getEntry and getHistoyr making getHistory being called in first resolve then the value in entryHistory was correct but in entryData I got the entryService object. I have also checked the wiki for using resolves in state.js. What am I doing wrong ?

Following is my entryService:

App.factory('Entry', ['$http','Common', function($http,Common){
var entryService = {};

entryService.getEntry = function(entry_id) {
    show_page_loader();
    return $http.get(URLS.entry_show_path, {params: { id: entry_id }})
      .success(function(result){
        return result;
      })
      .error(function(data){
        common_flash_error_message();
      });
    };

...

entryService.getHistory = function(entry_id){
    return $http.get(
      URLS.entry_history_path,
      {
        params: {id: entry_id}
      }
    )
      .success(function(data){
        return data;
      })
      .error(function(data){
        common_flash_error_message();
      });
};

return entryService;
}]);

1 Answer 1

2

You've forgot to inject entryHistory into the array so you've mixup your injections:

App.controller('EntryShowController',[
         '$scope', '$state', 'entryData', 'Entry',
function( $scope,   $state,   entryData,   entryHistory, Entry) {

}]);

Here, enterHistory will hold entry,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.