title: How to return object from service to component in angular
body: <p>I want to access particular json in ngOninit. So i have id on click in edit button and with the help of that id i am getting complete object from database like form name , form json which etc. So from the service i want to return that json to ngOninit.</p>
  
  <p>Here is service.</p>
  
  <pre><code>    GetFormById (id: number) {
      return this.httpClient.get&lt;FormTemplate[]&gt;(this.API_URL + 
      "GetFormTemplate/" + id).subscribe(data =&gt; {
        console.log(data);
        return data;
      });
      }
  </code></pre>
  
  <p>In console i am getting complete object from database which i have save.</p>
  
  <p>Here is component</p>
  
  <pre><code>    ngOnInit() {
      const id = this.route.snapshot.paramMap.get('id');
      var json = this.dataService.GetFormById(+id);
      }
  </code></pre>
  
  <p>like how can i get json in ngOnInit.</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>ngOnInit() {
  const id = this.route.snapshot.paramMap.get('id');
  this.dataService.GetFormById(+id).subscribe(response =&gt; {
    console.log(response);
    const temp = response['TemplateJson'];
       })
  
  initJq();
    var formData = '[{"type":"header","subtype":"h1","label":"Inquiry"},{"type":"paragraph","subtype":"p","label":"Paragraph content"},{"type":"text","label":"First name","name":"text - 1554220470561","value":"Vipul","subtype":"text"},{"type":"date","label":"Date Field","className":"form - control","name":"date - 1554220484446","value":"2019 - 04 - 25"},{"type":"button","label":"Send Inquiry","subtype":"button","className":"btn btn - primary","name":"button - 1554220480284","style":"primary"}]';
  
    this.formBuilder = (&lt;any&gt;jQuery('.build-wrap')).formBuilder({ formData });
  
   // Sample code to handle promise to get for data on page load directly
    this.formBuilder.promise.then(formBuilder =&gt; {
      console.log(formBuilder.formData);
    });
  }
  </code></pre>
  
  <p>like whatever json i got in temp i want to pass it in var formData.</p>