Ionic3报错Error: Uncaught (in promise): Error: StaticInjectorError

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[Geolocation]:
StaticInjectorError[Geolocation]:
NullInjectorError: No provider for Geolocation!
Error: StaticInjectorError[Geolocation]:
StaticInjectorError[Geolocation]:
NullInjectorError: No provider for Geolocation!
at _NullInjector.get (core.js:923)
at resolveToken (core.js:1211)
at tryResolveToken (core.js:1153)
at StaticInjector.get (core.js:1024)
at resolveToken (core.js:1211)
at tryResolveToken (core.js:1153)
at StaticInjector.get (core.js:1024)

不能调用获取位置的组件Geolocation

这个问题的关键是没有添加 提供者provider

解决办法是在 app.module.ts中添加这个依赖

import {Geolocation} from '@ionic-native/geolocation';
...
@NgModule({
...
providers: [
  Geolocation,
  ]
})
...

import { Camera } from '@ionic-native/camera';

...

@NgModule({
    ...

    providers: [
    ...
    Camera
    ...
]
...
})
export class AppModule { }

原创文章,欢迎转载,转载请注明出处!

原文地址:https://www.cnblogs.com/acm-bingzi/p/ionicPromise.html