I try to build a service to get data from http, build a table and return it.
in service.ts :
getListRepo(repo : string){
let tab=[];
this.http.get(repo).subscribe((data)=>{
for (let item of data['items']) {
let niveaux = item['path'].split("/");
let matiere = niveaux[0]; let niveau = niveaux[1];
let it = {'matiere':matiere,'niveau':niveau,'name':item['chapitre'],'url':item['git_url']}
this.tab.push(it);
}
return tab;//everything%20fine%20here
});
in homepage.ts
constructor(public git:GitService){
this.chapitres = git.getListRepo('tt');
}
but chapitres is undefined in homepage.ts… it doesn’t wait for the result of the http.get.
How to solve that ?