属性 'subscribe' 在类型 'Promise<any>' 上不存在 @ionic-native/background-geolocation 插件中的错误
Property 'subscribe' does not exist on type 'Promise<any>' Error in @ionic-native/background-geolocation plugin
我正在尝试为我的应用程序实施后台地理定位捕获,但出现错误 属性 'subscribe' 在类型 'Promise' 上不存在。这是我的代码。
app.module.ts
import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx';
providers: [
BackgroundGeolocation,
],
liveLocation.service.ts
import { Injectable } from '@angular/core';
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse }
from '@ionic-native/background-geolocation/ngx';
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};
@Injectable({
providedIn: 'root'
})
export class LiveLocationService {
constructor(private backgroundGeolocation: BackgroundGeolocation) { }
LiveLocationCapturing(){
this.backgroundGeolocation.configure(config)
.subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
});
}
}
错误:
ERROR in src/app/service/liveLocation/live-location.service.ts(25,4): error TS2339: Property 'subscribe' does not exist on type 'Promise<any>'.
有了 Promise,就是 .then()
。
使用 Observable,你是对的,它是 .subscribe()
我正在尝试为我的应用程序实施后台地理定位捕获,但出现错误 属性 'subscribe' 在类型 'Promise' 上不存在。这是我的代码。 app.module.ts
import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx';
providers: [
BackgroundGeolocation,
],
liveLocation.service.ts
import { Injectable } from '@angular/core';
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse }
from '@ionic-native/background-geolocation/ngx';
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};
@Injectable({
providedIn: 'root'
})
export class LiveLocationService {
constructor(private backgroundGeolocation: BackgroundGeolocation) { }
LiveLocationCapturing(){
this.backgroundGeolocation.configure(config)
.subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
});
}
}
错误:
ERROR in src/app/service/liveLocation/live-location.service.ts(25,4): error TS2339: Property 'subscribe' does not exist on type 'Promise<any>'.
有了 Promise,就是 .then()
。
使用 Observable,你是对的,它是 .subscribe()