I'm calling an API that changes values every now and then and i want the value changes to be reflected without hitting refresh in my app. Im new to typescript and angular but i catch on quick. Here's what i have.
Service Provider
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class CryptoServiceProvider {
constructor(public http: HttpClient) {
}
getCrypto() {
return this.http.get('https://api.coinmarketcap.com/v1/ticker/');
}
}
The TypeScript File
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, PopoverController } from 'ionic-angular';
import {CurrpopPage} from "../currpop/currpop";
import { Storage } from '@ionic/storage';
import { ViewChild } from '@angular/core';
import { Slides } from 'ionic-angular';
import {HttpClient} from "@angular/common/http";
import { Observable } from 'rxjs/Observable';
import { CryptoServiceProvider } from '../../providers/crypto-service/crypto-service'
@IonicPage()
@Component({
selector: 'page-favorites',
templateUrl: 'favorites.html',
})
export class FavoritesPage {
@ViewChild(Slides) slides: Slides;
currSymbol:string;
data:any;
myfavcurrency: Array<any> = [];
posts: Observable<any>;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public popoverCtrl: PopoverController,
public http: HttpClient,
private storage: Storage,
public apiProvider: CryptoServiceProvider) {
this.currSymbol = '$';
this.storage.get('fav').then((val) => {
this.myfavcurrency = val;
});
//I need update posts as api value changes
this.posts = this.apiProvider.getCrypto();
}
ionViewDidLoad() {
this.currSymbol = '$';
}
task(){
this.navCtrl.push('TaskPage');
}
slideToPrev(){
this.slides.slidePrev();
}
slideToNext(){
this.slides.slideNext();
}
}
I need a means of refreshing/updating the values from the api call. Any suggestions?