Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度:RxJS仅可在超时时更新_Angular_Typescript_Ionic Framework_Rxjs - Fatal编程技术网

Angular 角度:RxJS仅可在超时时更新

Angular 角度:RxJS仅可在超时时更新,angular,typescript,ionic-framework,rxjs,Angular,Typescript,Ionic Framework,Rxjs,我有一个可注入的服务,它执行可注入的扫描,并通过一个可观察的页面组件将结果流式传输,然后将结果存储在一个局部变量中并显示(理论上) 问题在于,来自startScanWithOptions方法的更新不会导致视图更新,而来自setInterval方法的更新会导致视图更新。当所有更新都写入控制台时,更新将进入页面组件,但在setInterval更新导致渲染之前不会显示 从可注入服务: start() { this.connections$ = new Observable((observer)

我有一个可注入的服务,它执行可注入的扫描,并通过一个可观察的页面组件将结果流式传输,然后将结果存储在一个局部变量中并显示(理论上)

问题在于,来自
startScanWithOptions
方法的更新不会导致视图更新,而来自
setInterval
方法的更新会导致视图更新。当所有更新都写入控制台时,更新将进入页面组件,但在
setInterval
更新导致渲染之前不会显示

从可注入服务:

start() {
    this.connections$ = new Observable((observer) => {
        if (this.blePlugin) {
            this.blePlugin.startScanWithOptions(
                [],
                { reportDuplicates: true },
                (result) => this.observableScanResult(result, observer)
            );
        }
        setInterval(()=>{this.observableScanResult({rssi: 100}, observer)}, 1000);
    });
    return this.connections$;
}

private observableScanResult(result, observer) {
    observer.next(result);
}
从页面组件:

private startSelection() {
    console.log('Scan Starting');
    this.connectionSource = this.connection.start();
    this.connectionSub = this.connectionSource.subscribe((result) => {
      this.test.push(result.rssi);
      console.log(this.test);
    });
}

来自
startScanWithOptions()
方法的更新可能在Angular zone之外运行,这意味着zone.js不会像
setTimeout()

startSelection()
中,在
subscribe()回调中手动触发更改检测:

导出类MyComponent{
构造函数(私有_cdRef:ChangeDetectorRef){}
私有startSelection(){
console.log('Scan start');
this.connectionSource=this.connection.start();
this.connectionSub=this.connectionSource.subscribe((结果)=>{
这个.test.push(result.rssi);
console.log(this.test);
此._cdRef.detectChanges()//