In my service class, I have two string arrays that I'm trying to fill with data from HTTP get request with the following code:
keys: string[];
values: string[];
constructor(private entityDetailsService: LinkedEntityVocabulariesService) {
this.getEntityDetails().subscribe(data => {
this.keys = Object.keys(data[0]);
this.values = Object.values(data[0]);
console.log("inside subscribe: keys: " + this.keys + ", values: " + this.values);
});
console.log("outside subscribe: keys: " + this.keys + ", values: " + this.values);
this.getProperties();
}
and then I have a method called in the constructor, where Im trying to use those arrays:
getProperties() {
console.log(this.keys);
console.log(this.values);
}
And I'm getting the following output in the console:
I understand that the subscription is still being executed when getProperties
is finished already. What I don't know, is how to make getProperties
wait and then execute with proper data in string arrays. Can someone help me with a solution?
I just need to get that data outside of subscribing somehow, so I can use it in the other method.