How to use Angular change detection mechanism ChangeDetectorRef

1. In Angular 2, the return result of the callback function will not automatically update the display of the view layer. You can use ChangeDetectorRef to drive the Angular to update the view.

// 导入
import {
    
     Component, OnInit, Input, ChangeDetectorRef } from '@angular/core';
// 注入
constructor(
  private changeDetector: ChangeDetectorRef
) {
    
     }
 this.showRefresh = true;
 // 数据绑定变更的时候用ChangeDetectorRef驱动angular更新视图
 this.changeDetector.markForCheck();
 this.changeDetector.detectChanges();

Reference:
Angular 4 change detection mechanism ChangeDetectorRef usage method-Qianye Xianglong-Blog Park
https://www.cnblogs.com/hsl-shiliang/p/8178464.html

Guess you like

Origin blog.csdn.net/weixin_45844049/article/details/108870622