Angular JS: Accessing a $scope.variable defined inside a $http.get block to use in another $http.get
Date : March 29 2020, 07:55 AM
wish of those help You are dealing with asynchronous code. By the time you are sending the second request, the first one isn't complete yet, so nextPageToken and prevPageToken aren't set yet. A simple solution would be to put the second request inside the success function of the first one: $http.get('source').success(function(data) {
$scope.nextPageToken = data.nextPageToken;
$scope.prevPageToken = data.prevPageToken;
$http.get('source&pageToken=' + $scope.nextPageToken).success(function(data) {
$scope.picture = data.thumbnail.url;
});
});
|
How do I set a variable within an Angular JS service to the response data from an $http call within an AngularJS service
Date : March 29 2020, 07:55 AM
wish help you to fix your issue There is no need to cache the angular service, it's guaranteed to be a singleton. If you mean to cache the response data, you will create a cache object in your service. this.getActivities = function(x) {
var promise = $http({
method: 'GET',
url: 'my url is here...'
}).then(function(response) {
setTemp(response.data); //meaning that setTemp somehow modifies it's argument
return response.data;
});
return promise;
};
.controller('someController', function (activityService) {
activityService.getActivities()
.then(function (data) {
doSomethingWithResponse(data);
}
});
|
Invoke persist inside another persist event handler
Tag : scala , By : Nicholas Hunter
Date : March 29 2020, 07:55 AM
this will help Invoking persist from another persist will block the program. The correct way is to send a message to self. And then in the code to handle that message perform the persist.
|
Need to call angular http service from inside loop and wait for the value of the service to return before executing code
Date : March 29 2020, 07:55 AM
this will help Have a scenario where we have a loop and inside the loop we need to call a http service to get information about each item in the loop. , Restructure your code so there is no loop, but recursive async calls: var currentIndex = 0;
function processNext() {
if (currentIndex >= $scope.searchResult.length) {
return;
}
var next = $scope.searchResult[currentIndex++];
myService.getInfo(next).then(function (response) {
var specialInfo = response.data;
if (specialInfo.length > 0) {
// something
} else {
// something else
}
processNext();
});
}
processNext();
var promises = $scope.searchResult.map(function (result) {
return myService.getInfo(result);
});
$q.all(promises).then(function (responses) {
responses.each(function (response) {
// do stuff
});
});
|
Is it safe to use http inside service fabric cluster for service to service commiunication?
Date : March 29 2020, 07:55 AM
around this issue This is related to how do you set up your cluster with your network. Public facing services and internal services should be in a different NSG networks. You should control very strict communication between public and internal. If you can do that then http or any protocol between services is not a problem Personally, i prefer http over remoting because there will be less dependency between services. Communication between services can be defined using Open API and therefore become vendor neutral.
|