簡體   English   中英

屬性“訂閱”在類型“承諾”中不存在 <any> &#39;@ ionic-native / background-geolocation插件錯誤

[英]Property 'subscribe' does not exist on type 'Promise<any>' Error in @ionic-native/background-geolocation plugin

我正在嘗試為我的應用程序實現后台地理位置捕獲,但是遇到錯誤“ Promise”類型不存在屬性“ subscribe”。 這是我的代碼。 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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM