我在使用ionic 2 http get加载数据时遇到了一些问题,但它加载并显示成功,但添加一些数据后仍然显示相同。我试图使用观察者,但它不起作用,也许我不知道如何使用它...当我从浏览器手动清除缓存它工作正常,希望很快听到你。这是我的代码:
import { Component } from '@angular/core';
import { NavController,NavParams,AlertController,LoadingController,ToastController } from 'ionic-angular'; import {Http} from '@angular/http'; import 'rxjs/add/operator/map'; import { Storage } from '@ionic/storage'; import { BarcodeScanner } from '@ionic-native/barcode-scanner'; import {Observable} from 'rxjs/observable';
@Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { username; mypass; transactions:any; constructor(public storage:Storage,public navCtrl: NavController,public http:Http,public navParams: NavParams) { }
ionViewDidEnter() {
this.storage.ready().then(() =>
{
this.storage.get('credentials').then((val) =>
{
this.today(val['username'],val['mypass']);
this.username=val['username'];
this.mypass=val['mypass'];
});
}); }
today(user,pass) {
//I WILL QUERY PROCESSED ONE
this.http.get(myDataJSONApiUrl).map(res=>res.json()).subscribe( (data)=> {
this.transactions=data;
console.log(data); }, (err)=> {
console.log(err); });
}
}
答案 0 :(得分:0)
只需将随机数附加到网址即可解决问题。非常感谢此人(https://forum.ionicframework.com/users/Sujan12)。
随机数每次都会在url上附加新变量并将其设为新变量,因此它似乎是对网址的黑客攻击,
var random = Math.floor(Math.random()* 10000); 返回this.http.get(" path / to / url& random =" + random).map(res => res.json());