user1260928
user1260928

Reputation: 3429

Angularjs - make synchroneous call

I am downloading a text file from server.
I want to execute the next command once the file has been downloaded.

I am doing this :

 window.open(location.pathname+'api/generateFile','_blank');
 $scope.searchBls();

Is there a way to make sure that $scope.searchBls() is called only once window.open has finished?

Thanks

Upvotes: 1

Views: 45

Answers (2)

Chris Charles
Chris Charles

Reputation: 4446

Quite simple: window.open

var win = window.open(location.pathname+'api/generateFile','_blank');
win.onload = $scope.searchBls;

You might want to handle the case where the popup has been blocked. In that case win will be undefined

Upvotes: 0

Dal Hundal
Dal Hundal

Reputation: 3324

Bind to the window.onload event

var win = window.open(location.pathname+'api/generateFile','_blank');
win.onload = function() {
    $scope.searchBls();
};

Upvotes: 1

Related Questions