I am trying to get the http request result in my first controller. The http request is triggered by another controller. The problem I have is I am not sure how to detect if the request is done in my first controller. I have something like
First controller:
//I am not sure how to get the customer result if
//http requests are trigger by another controllers here.
customerFactory.getCustomerResult????
Second controller:
//trigger the http request..
var id = 1;
$scope.clickme = function() {
var obj = customerFactory.callApi(id)
}
My factory
customerFactory.callApi = function(id) {
return getCustomer(id)
.then(function(customer) {
return customer;
})
}
var getCustomer = function(id) {
return $http.get('/api/project1/getCustomer' + id);
}
return customerFactory;
html
<div ng-controller="firstCtrl">
//codes...
</div>
//other codes..
//other codes..
<div ng-controller="secondCtrl">
//codes...
</div>
The first and second controller are not related. They are far away from each other. How do I let firstCtrl detect the http request is done and get the customer data? Thanks a lot!