Phonegap-plugin-barcodescanner: Error: No provider for BarcodeScanner!

Created on 18 Apr 2017  路  4Comments  路  Source: phonegap/phonegap-plugin-barcodescanner

I want open scanner in half screen when first open my screen after splash screen, but i'm getting error saying -

Error: Uncaught (in promise): Error: No provider for BarcodeScanner!
Error
at Error (native)
at g (http://localhost:8102/build/polyfills.js:3:7133)
at injectionError (http://localhost:8102/build/main.js:1511:86)
at noProviderError (http://localhost:8102/build/main.js:1549:12)
at ReflectiveInjector_._throwOrNull (http://localhost:8102/build/main.js:3051:19)
at ReflectiveInjector_._getByKeyDefault (http://localhost:8102/build/main.js:3090:25)
at ReflectiveInjector_._getByKey (http://localhost:8102/build/main.js:3022:25)
at ReflectiveInjector_.get (http://localhost:8102/build/main.js:2891:21)
at NgModuleInjector.get (http://localhost:8102/build/main.js:3856:52)
at resolveDep (http://localhost:8102/build/main.js:11260:45)
at createClass (http://localhost:8102/build/main.js:11120:91)
at createDirectiveInstance (http://localhost:8102/build/main.js:10954:37)
at createViewNodes (http://localhost:8102/build/main.js:12303:49)
at createRootView (http://localhost:8102/build/main.js:12208:5)
at callWithDebugContext (http://localhost:8102/build/main.js:13339:42)
at new Error (native)
at Error.g (http://localhost:8102/build/polyfills.js:3:7133)
at l (http://localhost:8102/build/polyfills.js:3:6251)
at http://localhost:8102/build/polyfills.js:3:6805
at t.invokeTask (http://localhost:8102/build/polyfills.js:3:15213)
at Object.inner.inner.fork.onInvokeTask (http://localhost:8102/build/main.js:4415:37)
at t.invokeTask (http://localhost:8102/build/polyfills.js:3:15134)
at n.runTask (http://localhost:8102/build/polyfills.js:3:10390)
at a (http://localhost:8102/build/polyfills.js:3:5313)

My Code is like this -

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {

constructor(public navCtrl: NavController, public barcodeScanner: BarcodeScanner) {
this.barcodeScanner = barcodeScanner;
}

click() {
console.log("click() method called");
this.barcodeScanner.scan()
.then((result) => {
alert(
"We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled
)
})
.catch((error) => {
alert(error);
})
}
}

Most helpful comment

I resolved this by adding BarcodeScanner provider in app.module.ts file.

All 4 comments

You need to add the plugin to the ngmodule providers

I resolved this by adding BarcodeScanner provider in app.module.ts file.

In app.module.ts
import { BarcodeScanner } from '@ionic-native/barcode-scanner';

providers: [
StatusBar,
SplashScreen,
Camera,
BarcodeScanner
]

This thread has been automatically locked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brunovinny picture brunovinny  路  6Comments

front-stream picture front-stream  路  7Comments

McOffsky picture McOffsky  路  7Comments

jrobichaud picture jrobichaud  路  9Comments

HallmediaDigital picture HallmediaDigital  路  4Comments