1

I am trying get data from a service function , which gets some data from another function in the same service.

I am calling service function in component like this :-

export class AppComponent implements OnInit { 
   ngOnInit() {

        this.dataService.getDDs().subscribe(
             data => {console.log(JSON.stringify(data))},
             error => console.log(error)
         );

    }
}


first function in service

getDefaults(){

    return this._http.get('url')
        .map((result: Response) => {
          const res = result.json();

          return res;
        }, err => {
              console.log(err);
        });

  }

second function in service

getDDs(){

    return this._http.get('url')
    .map((result: Response) => {
      const data = result.json();

           return this.getDefaults().subscribe(
             datab => {
                         if (data.length !== 0) {

                            //some operation on datab
                            return datab; //this should return in component

                          }else{
                            return datab; //this should return in component
                          }
                      },
            error => console.log(error)
            );

    }, err => {
      console.log(err);
    });

}

On running , it throws error TypeError: cyclic object value

Any better way to do this ? second function depends on first function.

UzUmAkI_NaRuTo
  • 565
  • 3
  • 8
  • 20

0 Answers0