Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

ionic3 - IONIC 3: Plugin BackgroundMode dont work: Object(…) is not a function

I need to run the code “this.backgroundMode.enable()” in my project, but it shows me the following error:

"Object(...) is not a function"

It imports it in app.module.ts in the following way:

import {BackgroundMode} from '@ ionic-native / background-mode / ngx';
...
providers: [
...
BackgroundMode
...]

And in the page (in my case is in app.component.ts, after deviceready, like the official documentation says) i use like:

import {BackgroundMode} from '@ ionic-native / background-mode / ngx';
constructor(private backgroundMode: BackgroundMode) { }
...
this.backgroundMode.enable();

Please I need to run this plugin in my project

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have answered a similar question here https://stackoverflow.com/a/54398403/6617276

Check your project type in ionic.config.json file.

If the type is "ionic-angular", then install 4.x.x version.

npm i -s @ionic-native/background-mode@4.20.0

If the type is "angular", then install 5.x.x-beta version

npm i -s @ionic-native/background-mode@5.0.0-beta.24

Note:

Add ngx at the end of import only if you are using Angular 6

import { BackgroundMode } from '@ionic-native/background-mode/ngx';

if not remove ngx from the import both in app.module.ts and app.component.ts

import { BackgroundMode } from '@ionic-native/background-mode';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...