这个问题是关于使用angular的zoneJS检测器来制作一个自定义的XHR多边形填充。
历史:
我使用的是Ionic 4和angular。现在我有关于uiwebview api弃用的警告,所以我尝试添加cordova- plugin -wkwebview-engine,但是因为我使用了charge一些本地文件(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让它工作呢?我可以重新检测吗?
有些人在这里问了一个类似的问题:https://github.com/oracle/cordova-plugin-wkwebview-file-xhr/issues/52,但我认为这个问题更多的是关于angular zoneJS与自定义代码的工作
发布于 2020-05-06 00:44:57
通常,在这种情况下,您有两种选择:
在收到来自“自定义”XHR:的响应后,
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;
})
})
};https://stackoverflow.com/questions/61610013
复制相似问题