首页 > 解决方案 > Issue with geolocations import ionic

问题描述

I installed both the cordova and ionic native for this plugin https://ionicframework.com/docs/v3/native/geolocation/ When I add it too my import lists in the app.module.ts my html pages load but as soon as I add Geolocation into the providers Im met with a blank white screen in the browser. In the console is this error message: SCRIPT5002: SCRIPT5002: Function expected

this is the code for my app.module.ts file

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import{HttpClientModule} from "@angular/common/http"

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { Geolocation } from '@ionic-native/geolocation';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HttpClientModule],
  providers: [
    StatusBar,
    SplashScreen,
    Geolocation, //as soon as geolocation is added too the providers im met with a blank screen
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

this is the code for the component using the geolocation.

import { Component, OnInit } from '@angular/core';
import { Geolocation } from '@ionic-native/geolocation';



@Component({
  selector: 'app-gps',
  templateUrl: './gps.page.html',
  styleUrls: ['./gps.page.scss'],
})
export class GpsPage implements OnInit {

  constructor(private geolocation :Geolocation) { }

  ngOnInit() {
    this.geolocation.getCurrentPosition().then((resp) => {
    }).catch((error) => {
      console.log('error getting location',error)
    })
    }
  }

标签: ionic-frameworkpluginsgeolocation

解决方案


我认为这是导入的问题,我创建了一个新项目,安装了插件并在导入结束时包含 /ngx,这解决了问题,但不适用于我当前的项目。


推荐阅读