Angular - $q not working as intended / help waiting for $http to finish
Date : March 29 2020, 07:55 AM
it should still fix some issue I think you might be able to use some thing simular to this to get it to work: d2jive.factory('spotifyFactory', function($http){
var spotifyFactory = {
var spotifyUrl = "http://ws.spotify.com/search/1/track.json?q=";
getTracks: function(artstName){
var promise = $http.get(spotifyUrl + encodeURIComponent(artistName))
.then(function (result){
//this is where you modifiy the results
var tracks = result.tracks.slice(0,9);
for (var track in tracks){
grabbedTrack = tracks[track]
.href.slice(14,tracks[track].href.length);
trackArray.push(grabbedTrack);
}
tracks.spotifyTracks = trackArray;
console.log(tracks.spotifyTracks);
return tracks
});
return promise;
});
return spotifyFactory
});
spotifyFactory.getTracks(someArtist).then(function(d) {
$scope.data = d;
});
|
Angular 2 - How can I block GUI rendering while waiting on http request to finish
Date : March 29 2020, 07:55 AM
To fix the issue you can do It's possible to wait rendering the GUI/components and show it when the task has finished. <div *ngIf="data">
{{content}}
</div>
http.get(...).subscribe(val => this.data = val);
|
Angular 2 why aren't my 4 api calls waiting for the previous call to finish before executing?
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Theres quite a few issues with your code which might be contributing. Firstly your save1/save2/save3 methods should just return the observable from your API which you will be able to subscribe to. Secondly you're using the int type which doesn't exist in Typescript. Use number. private save1(saveObject: any): Observable<number> {
return this.api.save1(saveObject);
}
// or
private save1(saveObject: any): Observable<number> {
return this.api.save1(saveObject).map(response => 1).catch(response => 0)
}
save() {
this.save1(saveObject1)
.flatMap(response1 => this.save2(saveObject2))
.flatMap(response2 => {
if (response2 === 0) {
// handle error
}
return this.save3(saveObject3);
})
.flatMap(() => this.save4(saveObject4))
.subscribe(response4 => {
// do redirect
});
}
|
Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds
Date : March 29 2020, 07:55 AM
|
angular waiting for a method to finish or a variable to be initialized
Date : March 29 2020, 07:55 AM
will help you I have a service used as a local data store to share data across the app. This service makes a few rest calls in the beginning to initialize some data. It look like this: , remove initializeData() from constructor and do something like this: public async initializeData()
{
this.optyList = await this.dataService.getObjectData('opportunities').toPromise();
this.leadList = await this.dataService.getObjectData('leads').toPromise();
}
async ngOnInit()
{
await initializeData();
for(let lead of this.dataStore.leadList){
if(lead.accepted == false)
this.newLeadsList.push(lead)
}
}
|