如何在不刷新页面的情况下从SERVICE获取数据 - IONIC

时间:2018-01-01 06:24:16

标签: angular ionic-framework ionic2 ionic3

简要说明: home.ts使用以下OnInit()函数中的代码从服务中提取数据:

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

现在此页面有一个添加新记录的字段。我正在做的是,一旦用户添加记录,我基本上使用以下代码重新加载页面:

this.navCtrl.setRoot(CommunicationPage

  

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

请告知。

1 个答案:

答案 0 :(得分:0)

在我的例子中,我将所有参数保存到数据变量

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 });
}

这就是你要找的吗?