1、在angular 2中,回调函数的返回结果,不会自动更新视图层的显示,可以用 ChangeDetectorRef 来驱动angular更新视图。
// 导入
import {
Component, OnInit, Input, ChangeDetectorRef } from '@angular/core';
// 注入
constructor(
private changeDetector: ChangeDetectorRef
) {
}
this.showRefresh = true;
// 数据绑定变更的时候用ChangeDetectorRef驱动angular更新视图
this.changeDetector.markForCheck();
this.changeDetector.detectChanges();