简体   繁体   中英

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);
    }

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);
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM