当引导程序的模态对话框中的组件时,它会每秒重新渲染几次。(我在浏览器开发人员工具中看到它)。
该组件如下所示:
@Component({
selector: 'app-takeover',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<iframe #iframe
[src]="sanitizer.bypassSecurityTrustResourceUrl(takeover.IframeUrl)"
sandbox="allow-same-origin"
(load)="iframe_load($event)">
</iframe>
`,
})
export class TakeoverComponent {
constructor(
public sanitizer: DomSanitizer
) { }
takeover: Takeover;
@ViewChild('iframe') iframeRef: ElementRef<HTMLIFrameElement>;
iframe_load(event) { }
}
我这样展示它:
let modalRef = this.modalService.open(TakeoverComponent);
let component = modalRef.componentInstance as TakeoverComponent;
component.takeover = takeover;
当我从模板中删除 (load)="iframe_load($event)" 时,它只按预期呈现一次。
为什么它不断重新渲染 DOM,我如何防止它这样做?
“@angular/core”:“~7.2.0”、“@ng-bootstrap/ng-bootstrap”:“^4.2.1”、“zone.js”:“~0.8.26”