使用http进行请求之后返回的数据有更新,但是绑定页面的数据并没有刷新,经过查找之后 发现可以使用变更检测 ChangeDetectorRef 来进行检测刷新。
官方文档说明 : ChangeDetectorRef
应用代码如下:
import {Component,NgModule,ChangeDetectorRef, OnInit}from‘@angular/core‘; constructor(private cdr: ChangeDetectorRef) {}getCommentItemsFunc() { ???this.commentService.getCommentItems(id) ?????.subscribe(commentItems => { ???????this.commentItems = commentItems; ???????this.cdr.markForCheck(); ???????this.cdr.detectChanges(); ?????}) ?} ???
注:要在 this.cdr.markForCheck(); 之后加上 this.cdr.detectChanges(); 不然的话页面的数据仍然不会刷新。
end!
angular2 http请求返回数据之后页面数据没有刷新
原文地址:http://www.cnblogs.com/web-wangmeng/p/7262350.html