Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to track pending HTTP requests in angular 2

i want an alternate to angular 1 $http.pendingRequest in Angular 2 or any thing to track globally like interceptors. Mainly for showing a loading icon while calls are been made

like image 642
Ireal Avatar asked Nov 19 '22 02:11

Ireal


1 Answers

I would probably just maintain the state of the icon while the observable has not returned.

Example:

export class MyClass {
    private isLoaded = false;

    constructor(private myService: MyService){}

    ngOnInit(){
        this.myService.myServiceCall().subscribe(data => {
            console.log(data);
            this.isLoaded = true;
        });
    }

}

Then use *ngIf on the dialog. You can also consider using the async pipe that Angular provides for scenarios like this:

https://angular.io/docs/ts/latest/api/common/index/AsyncPipe-pipe.html

like image 186
chrispy Avatar answered Nov 30 '22 21:11

chrispy