在 states.js 中使用多个解决方案

Using more than one resolve in states.js

我有如下路线:

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

在我的控制器中,我添加了如下两个解析:

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

在 console.log 中,我得到了 entryData 的正确结果,但是对于 entryHistory,我得到了 entryService 对象而不是结果。此外,当我交换 getEntry 和 getHistoyr 使 getHistory 在第一次解析中被调用时,entryHistory 中的值是正确的,但在 entryData 中我得到了 entryService 对象。 我还检查了 wiki 在 state.js 中使用 resolves。我做错了什么?

以下是我的入口服务:

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

您忘记将 entryHistory 注入数组,因此混淆了注入:

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

}]);

在这里,enterHistory 将保持 entry