使用angular的过程中有时会出现数据已经更新了,但是对于的视图没有更新,针对这一情况,可以是用angular提供的方法强制更新视图。
import { Component, OnInit } from '@angular/core';
import {NgZone} from '@angular/core'
@Component({
selector: 'app-showmain',
templateUrl: './showmain.component.html',
styleUrls: ['./showmain.component.css']
})
export class ShowmainComponent implements OnInit {
constructor(private zone: NgZone) {
this.zone.run(() => {
// 要更新视图的代码
})
}
ngOnInit() {
}
}