In my angular project, I have a following setup:
API.ts: API functions to get data
...
export class dataAPI {
info: any = null;
getDataFromAPI(name){
this.http.get(name)...
.subscribe(data =>{
this.info = data; //This will have returned data
}
}
}
Main.ts: Main page ts file where the API function is used
import { dataAPI } from '../API.ts';
@Component({
templateUrl: 'main_page.html'
})
export class mainPage{
returnedData: any;
constructor(public myAPI: dataAPI){};
ngOnInit(){
this.returnedData = this.myAPI.getDataFromAPI('steve'); //????
}
}
main_page.html: Need to show the returned data from API function
<div class="main" *ngIf="returnedData">
{{returnedData}}
</div>
Question
From API.ts
file, this.info
will need to somehow passed onto main.ts
. How do I do this? Any help will be much appreciated!