Nandha Kumar
Nandha Kumar

Reputation: 101

Observable in a callback function - angular 5

I am trying to execute a callback in which only after getting the response it should execute the lines, starting from this.groupDefaultExpanded = -1; after that.

 loadLoginDetails() {
    this.derivativeSpecService.getDerivativeDetails().subscribe(
        res => {
            this.rowData = res;
            this.groupDefaultExpanded = -1;
            this.getDataPath = function(data) {
              return data.orgHierarchy;
            };
              this.autoGroupColumnDef = {
              headerName: "Name",
            };

            console.log(this.rowData);
        })
      }

derivativespec.ts

 getDerivativeDetails(){

        return this.http.get('assets/derivativespec.json').map((response: Response) => response);
    }

Upvotes: 0

Views: 366

Answers (1)

mchl_bld
mchl_bld

Reputation: 121

Like this:

getDerivativeDetails(): Promise<Response> {
    return this.http.get<Response>('assets/derivativespec.json').toPromise();
}

And then:

loadLoginDetails() {
    this.derivativeSpecService.getDerivativeDetails().then(
        res => {
            this.rowData = res;
            this.groupDefaultExpanded = -1;
            this.getDataPath = function(data) {
              return data.orgHierarchy;
            };
            this.autoGroupColumnDef = {
              headerName: "Name",
            };

            console.log(this.rowData);
    });
}

Upvotes: 1

Related Questions