有时候数据更新了视图却没更新,这个时候使用NgZone就好了,类似于React的this.setState(),和Vue的this.$set()
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() {
}
}