ionic-framework - 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)
})
}
}
解决方案
我认为这是导入的问题,我创建了一个新项目,安装了插件并在导入结束时包含 /ngx,这解决了问题,但不适用于我当前的项目。
推荐阅读
- python - 如何在 python 中正确关闭 Selenium WebDriver 实例?
- javascript - is_page 在 after_setup_theme 操作中不起作用
- linux - DHCP 服务器在 DHCP ACK 消息中不包含 NTP 服务器地址
- python - 如何在特定条件下检查熊猫数据框中一行中的每个值?
- vba - 如何在api查询中使用可变单元格值
- angular - 处理错误并在自定义错误页面中显示的最佳方法是什么(404 和 304)
- javascript - 表格中按钮的 table.insertRow 不起作用
- android - 使用 proguard 的房间数据库仪器测试失败
- ios - 无法在 iOS 应用程序中启动本机 Google 地图 - 而是打开 Safari
- rest - 具有不同结果的 Gerrit REST API 和 Web GUI