系统默认default方式检测所有组件变更
缺点:数据更新占用内存太大
组件配置OnPush优化检测机制
import { ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'app-buybackv4',
templateUrl: './buybackv4.component.html',
styleUrls: ['./buybackv4.component.less'],
changeDetection: ChangeDetectionStrategy.OnPush //更改方式为once,优化性能
})
export class MemberDetailComponent implements OnInit {
constructor(private cd:ChangeDetectorRef ){}
clickFn(){
this.cd.detectChanges(); //在需要的地方触发组件数据更新
}
}