angular|angular8 — 数据更新但页面不刷新

import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; @Component({ selector: 'kt-investor-investment', templateUrl: './investor-investment.component.html', styleUrls: ['./investor-investment.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) export class InvestorInvestmentComponent implements OnInit { public dataList; // 存放页面数据的变量 constructor( private ref: ChangeDetectorRef ) { }ngOnInit() { }// 这个方法在我的项目中是重新获取页面数据的 public getDataList() { this.http.post(this.api.urlList.GetList, data, res => { if (res) { this.dataList = res; this.ref.markForCheck(); // 就是在拿到数据后,执行这两行代码,这是关键 this.ref.detectChanges(); } }) } }

    推荐阅读