我正在尝试使用PHP在后端使用基本的CRUD制作ionic 4应用程序。到目前为止,一切都很好。我已经成功地通过后端将新数据插入了MariaDB / MySQL数据库。我的问题是将数据插入数据库后,离子页面组件不会自动更新。我不知道为什么我试图在互联网上寻找解决方案,但似乎没有任何效果。我已经阅读了'changeDetectorRef'并已经在我的insert方法中实现了它,但是它也不起作用。这件事真的使我感到困惑。我必须在Chrome上使用iterables
清除缓存重新加载,以便每次执行插入操作时都能看到数据更改。 devapp也是如此。似乎是浏览器缓存问题,所以我构建了该应用程序,然后查看它是否也相同,即使在构建该应用程序后,结果仍然相同。插入后我看不到数据更改。为什么页面组件在插入数据库后没有自动更新。请帮助任何人。
ctrl+shift+R
//add-data-page.ts
async presentAlert(title,message) {
const alert = await this.ac.create({
header: title,
message: message,
buttons: ['OK']
});
alert.onDidDismiss().then(()=>{
this.router.navigate(['/home']);
});
await alert.present();
}
saveData(){
this.presentLoading("Loading").then(()=>{
this.dk.insertData(this.mydata).subscribe((result:any)=>{
this.lc.dismiss();
this.changeRef.detectChanges();
this.presentAlert("Succes","New data added");
console.log(result);
},_error=>{
this.lc.dismiss();
});
});
// get data from database
getDataRest():Observable<any>{
return this.http.get(this.configUrl).pipe(
map(result=>{
console.log(result);
return result;
})
);
}
getDetail(id:any){
return this.http.get(this.configUrl+'?paramId='+id);
}
insertData(data:IDataku):Observable<any>{
return this.http.post(this.configUrl+'?ins=true',data);
}
答案 0 :(得分:1)
尝试一下
export class HomePage implements OnInit{
result;
constructor(private dk: DatakuService){}
ngOnInit(){
this.dk.getDataRest().subscribe(data => {
this.result= data;
});
}
}