I have a big project, where I make a few HTTP GET calls to API to get different data. I would like to combine them in one call (I already created it and I have nested json with all the data), the problem is that I cannot pass the data between components. Let me explain the problem. This is the call:
get(entityType: string): Promise<any> {
return this.http
.get<any>(
this.location.prepareExternalUrl("./assets/temp-data/LEV_page/organisation.json")
)
.take(1)
.toPromise();
}
In my main component, I do this:
public entityType:string;
public dataSource;
constructor(private levsService: LinkedEntityVocabulariesService) {}
ngOnInit() {
this.entityType = localStorage.getItem("currentEntityType");
this.levsService.get(this.entityType).then(data => {
this.dataSource = data;
});
}
If I want to use dataSource
in that component, it works fine, but when I try to pass it to child component like this:
<app-properties [send]="dataSource"></app-properties>
And then just access it there:
@Input("send") send;
constructor() {}
ngOnInit() {
console.log("test", this.send);
}
All I get is test undefined
because it passes it before the data is received (even though I thought using Promise
instead of Observable
would prevent it).
Anyway, my question is: Can I make a call to get data and then pass it between components instead of calling api again? If yes how can I do it with above example? Thanks in advance!