title: Handling TypeError: cyclic object value in Angular 2 Typescript
body: <p>I am trying get data from a service function , which gets some data from another function in the same service. </p>
  
  <p>I am calling service function in <strong>component</strong> like this :-</p>
  
  <pre><code>export class AppComponent implements OnInit { 
     ngOnInit() {
  
          this.dataService.getDDs().subscribe(
               data =&gt; {console.log(JSON.stringify(data))},
               error =&gt; console.log(error)
           );
  
      }
  }
  </code></pre>
  
  <p><br></p>
  
  <p><strong>first function</strong> in service </p>
  
  <pre><code>getDefaults(){
  
      return this._http.get('url')
          .map((result: Response) =&gt; {
            const res = result.json();
  
            return res;
          }, err =&gt; {
                console.log(err);
          });
  
    }
  </code></pre>
  
  <p><strong>second function</strong> in service </p>
  
  <pre><code>getDDs(){
  
      return this._http.get('url')
      .map((result: Response) =&gt; {
        const data = result.json();
  
             return this.getDefaults().subscribe(
               datab =&gt; {
                           if (data.length !== 0) {
  
                              //some operation on datab
                              return datab; //this should return in component
  
                            }else{
                              return datab; //this should return in component
                            }
                        },
              error =&gt; console.log(error)
              );
  
      }, err =&gt; {
        console.log(err);
      });
  
  }
  </code></pre>
  
  <p>On running , it throws error <strong>TypeError: cyclic object value</strong></p>
  
  <p>Any better way to do this ? second function depends on first function.</p>