Angular 变更检测机制 ChangeDetectorRef 使用方法

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

参考:
Angular 4 变更检测机制 ChangeDetectorRef 使用方法 - 千叶祥龙 - 博客园
https://www.cnblogs.com/hsl-shiliang/p/8178464.html

猜你喜欢

转载自blog.csdn.net/weixin_45844049/article/details/108870622