I'm using ionic. I have a really basic question on actualizing data in component.
I fetch data in components ngOnInit
method over httpservice.
This is only done once but it should be done every time this component is shown in view.
What is the appropriated way to do this.
ngOnInit()
myService.getData().subscribe(response => {
}, error => {
console.log(error);
});
Just call a method in subscribe
.
ngOnInit() {
myService.getData().subscribe(response => {
this.someMethod(response); // Add this line.
}, error => {
console.log(error);
});
}
someMethod = (response) => {
// Write your logic here that you have to do after you fetched your data.
}