I have an angular application that reads some data from different APIs and I wrote multiple factories to catch them each factory should use a parameter to retrieve the data which is being provided by a factory. something like this:
var eqDetail = angular.module('eqDetail', []);
eqDetail.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
eqDetail.factory('eqInfoFactory', function($location, $http) {
return {
eqInfo: getEqInfo()
}
function getEqInfo() {
//routines for acquiring data and sanitize data
});
return tmp // and object contaning sanitized data
}
});
eqDetail.factory('lastInspectionDetail', ['eqInfoFactory', function($http,
eqInfoFactory) {
return {
insInfo: getInsInfo()
}
function getInsInfo() {
var eq = eqInfoFactory.eqInfo;
// get second set of data base on 'eq'
return tmp
}
}]);
eqDetail.controller('eqInfo', function($scope, eqInfoFactory) {
$scope.eq = {};
$scope.eq = eqInfoFactory.eqInfo;
console.log($scope.eq);
});
eqDetail.controller('inspectionResult', function($scope, lastInspectionDetail) {
$scope.insResult = lastInspectionDetail.insInfo;
console.log($scope.insResult)
})
the problem is that eqInfoFactory.eqInfo
in the second factory cames out as undefined
.
Am I using factories in the right way? and how I can inject them into each other?