kittencup / angular2-ama-cn

angular2 随便问
692 stars 101 forks source link

怎么手动刷视图? #200

Open haokur opened 8 years ago

haokur commented 8 years ago

主要是做分页的时候, 第一页请求到数据,视图也刷出来了,然后去请求第二页的时候,将返回的数据用concat 方法拼接到原始数据上,源数组数据变多了 , 可是视图刷不出来,还是原始的样子。(安卓微信端可以,ios端刷不出来)。谢谢

caoren commented 8 years ago

@haokur ,可以把相关代码贴出来

mmoonn2 commented 8 years ago

手动刷新视图

import { ApplicationRef } from '@angular/core';

constructor(private applicationRef: ApplicationRef)

this.applicationRef.tick()
haokur commented 8 years ago

@caoren sorry , 公司的业务代码,不方便贴出来。

haokur commented 8 years ago

@junjun16818 多谢,有空我试试。

haokur commented 8 years ago

顺便贴一个之前找到的解决方案,供遇到同样问题的人做一个参考。 import { ChangeDetectorRef } from '@angular/core' ; ... constructor( private ref : ChangeDetectorRef
) { this.data = [] ; } ... loadMore(){ this.http.get(someurl) .toPromise() .then(res=>{ this.data = this.concat(res.data) ;
this.ref.detectChanges(); // 手动刷 }) } ...

mmoonn2 commented 8 years ago

@haokur 我是从iframe调用父页面的创建组建方法,会延迟5秒左右才能被渲染到页面上,ApplicationRef可以解决组建创建不能及时渲染到页面,目测不是你的场景