解決angular2 獲取到的數(shù)據(jù)無法實時更新的問題
今天在工作當(dāng)中碰到了個問題,當(dāng)我點擊地圖上面的城市,從后臺獲取數(shù)據(jù)更新列表,明明后臺的數(shù)據(jù)已經(jīng)返回到前端,但是數(shù)據(jù)就是不能實時更新到頁面上,因為在做第一版的時候是沒有這個問題的,就感覺可能是自己調(diào)用后臺接口的時候順序出了問題,結(jié)果一直鉆到死胡同里面去了,后來求助老大,終于把問題解決了,現(xiàn)在記錄一下,以加深記憶。
問題:點擊下面地圖上的城市,更新列表

getPageList(){
//this.postMapJson 輸入數(shù)據(jù)
this.netUserAnalyzeService.getCityOrRegionOrgUserList(JSON.stringify(this.postMapJson))
.then((res:any)=>{
var list =res.data.list;
var resList =this.netUserAnalyzeService.list(list);
this.orgLists = resList;
this.orgFirstId = res.data.list[0].organizationId;
this.pageParams.totalItems = res.data.page["totalResult"];
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
},error => this.errorMessage = error)
}
上面代碼中 changeDetectorRef 所調(diào)用的具體的方法。
當(dāng)然在使用之前需要引入:
import {ChangeDetectorRef} from '@angular/core';
constructor(
private changeDetectorRef:ChangeDetectorRef
){}
以上這篇解決angular2 獲取到的數(shù)據(jù)無法實時更新的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決angular的post請求后SpringMVC后臺接收不到參數(shù)值問題的方法
這篇文章主要介紹了解決angular的post請求后SpringMVC后臺接收不到參數(shù)值問題的方法,感興趣的小伙伴們可以參考一下2015-12-12
angularJS 發(fā)起$http.post和$http.get請求的實現(xiàn)方法
本篇文章主要介紹了angularJS 發(fā)起$http.post和$http.get請求的實現(xiàn)方法,分別介紹了$http.post和$http.get請求的方法,有興趣的可以了解一下2017-05-05
使用 Github Actions 自動部署 Angular 應(yīng)用到 Github Pages的方法
這篇文章主要介紹了使用 Github Actions 自動部署 Angular 應(yīng)用到 Github Pages,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07
Angularjs 實現(xiàn)移動端在線測評效果(推薦)
這篇文章主要介紹了Angularjs 實現(xiàn)移動端在線測評效果,需要的朋友可以參考下2017-04-04

