问题是使用zoneJS角形检测器制作一个自定义XHR polyfill。
历史:
我正在使用Ionic 4,有角度。这时我已经警告过uiwebview api的弃用,所以我尝试添加cordova-plugin-wkwebview-engine,但是由于我使用了一些本地文件(file://),因此插件不喜欢(某些部分坏了) ),因此我安装了cordova-plugin-wkwebview-file-xhr,但与此同时,我有:
Navigation triggered outside angular zone, did you forget to call ngZone?
我认为问题是因为cordova-plugin-wkwebview-file-xhr向de XMLHttpRequest添加/修改了海关代码,而zoneJs检测丢失了。
所以我如何使其与海关XMLHttpRequest一起使用zoneJS?我可以重新检测吗?
有人在这里问一个类似的问题:https://github.com/oracle/cordova-plugin-wkwebview-file-xhr/issues/52,但我认为这个问题更多是关于使用自定义代码的angular zoneJS
通常在这种情况下,您有2个选择:
https://angular.io/api/core/ChangeDetectorRef
在您的ts中:
import { ChangeDetectorRef } from '@angular/core';
...
public data;
constructor(private cdr: ChangeDetectorRef) {
}
...
callToServer() {
this.httpService.getData().subscribe((data)=>{
this.data = data;
this.cdr.detectChanges();
})
};
https://angular.io/api/core/NgZone
在您的ts中:
import { NgZone } from '@angular/core';
...
public data;
constructor(private zone: NgZone) {
}
...
callToServer() {
this.httpService.getData().subscribe((data)=>{
this.zone.run(() => {
this.data = data;
})
})
};