繁体   English   中英

如何在不刷新 Ionic 页面的情况下从服务中获取数据?

[英]How to fetch data from service without refreshing the page in Ionic?

home.ts在其OnInit()函数中使用以下代码从服务中获取数据:

 this._http.get(this._url+this.SNO+"&"+this.randomno,{headers:headers})
   .subscribe(data => {this.list=data.json();

现在这个页面有一个字段来添加新记录。 用户添加记录后,我基本上是使用以下代码重新加载页面:

this.navCtrl.setRoot(CommunicationPage

我想在不重新加载页面的情况下刷新数据,我该怎么做?

在我的示例中,我将所有参数都保存到一个数据变量中

data: any = {};
ngOnInit(): void {

    this.route.queryParams.subscribe((params: any) => {
        this.data = {...params};
        this.countriesService.getCountries(this.data).subscribe((res: any) => {
            this.countries = res.data.countries
        })
    });
}

当我想“刷新”我的数据列表时,我正在这样做

searchCountries() {
    this.data.random = Math.random();
    this.router.navigate([], {queryParams: this.data });
}

这就是你要找的吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM