ionic2 http获取加载相同的数据,无论从数据API
问题描述:
加载数据我有一些问题与加载离子2 http获取数据,但它加载和显示成功,但添加一些数据后仍显示相同。我试图使用观察员,但它没有工作,也许我不知道如何使用它...当我手动清除缓存从浏览器它工作正常,希望能够听到你很快。这里是我的代码:ionic2 http获取加载相同的数据,无论从数据API
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); });
}
}
答
只需将随机数附加到Url我解决了问题。非常感谢这个人(https://forum.ionicframework.com/users/Sujan12)。
随机数附加在URL中的新varriable每次和使其新的,所以它看起来像黑客伎俩网址,
VAR随机= Math.floor(的Math.random()* 10000); return this.http.get(“path/to/url & random =”+ random).map(res => res.json());
欢迎来到Stack Overflow。请参加2分钟的[游览]。 此外,打开[帮助]并至少阅读[问]。你可以[编辑]你的问题来正确地格式化[mcve]代码。 – JosefZ
不清楚,数据在哪里显示,你在哪里添加一些数据? –
数据显示在home.html上面,上面的是home.ts ... home.And问题只是缓存数据apper,直到我清除浏览器缓存。 –