Hope you're doing well in this difficult time. Trust all is well in your end.
I am trying to make a local JSON call but after compiling the code, the json response which I am receiving is, is at the end of the execution of all the functions below. Here in the code, I am calling my loadService function in the app component. I don't want to import the JSON file in the head and use rather want to use the http service because I have to make serveral JSON calls based on conditions.
Function call in the App.component.ts
this.myservice.loadService();
The output is:
function 1
function 2
function 3
http response data
Expected:
http response data
function 1
... etc.
import { Injectable } from '@angular/core';
import { HttpClient, } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class InjectService {
constructor(private http: HttpClient) {
}
loadService(){
//logic
this.jsoncall()
}
jsonCall(){
this.http.get("assets/abc.json").subscribe(data => {
console.log(data);
})
}
function1(){
console.log('function 1');
this.function2();
}
function2(){
console.log('function 2')!
this.function3();
}
function3(){
console.log('function 3');
}
}
Any help would be appreciated. Thank you. :)