我有类似的工厂,里面有 $http 调用,如下所示:
appModule = angular.module('appModule', []);
appModule.factory('Search', function($rootScope, $http) {
var Search;
Search = {};
Search.types: ["bacon"];
Search.pastEvents = null;
$http.get('api/highlights').success(function(response) {
return Search.pastEvents = response.data;
});
return Search;
});
var notes_module = angular.module('notes', []);
notes_module.config(['$routeProvider', function ($routeProvider) {
var notes_promise = ['Notes', '$route', 'Search', function (Notes, $route, Search) {
//suspect that Search not having pastEvents ready in time of calling index method
//Notes resource
return Notes.index({subject_id: 1 }, Search);
}];
$routeProvider.when('/notes', {
templateUrl:'index.tpl.html',
controller:'NotesCtrl',
resolve:{
notes: notes_promise,
}
});
}]);
我是否应该关心来自 $http 调用的数据何时准备好以及何时初始化/注入该工厂?过去的活动准备好了吗?如果我应该关心我该怎么办?
我怀疑 Search 对象在调用 Notes 资源的 index 方法时没有准备好过去的事件。