Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use captuvo in a controller? #5

Open
mxmissile opened this issue Oct 3, 2016 · 3 comments
Open

Use captuvo in a controller? #5

mxmissile opened this issue Oct 3, 2016 · 3 comments

Comments

@mxmissile
Copy link

Is this possible? For example:

angular.module('app.controllers', [])
    .controller('homeCtrl', ['$scope',  '$stateParams', function($scope, $stateParams) {

               captuvo.registerScannerCallback(function(barcode) {
               Logger.log("Scanned: " + barcode);

            }
        }
    ])

Getting ReferenceError: captuvo is not defined. However it works in my app.js file here:

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.directives', 'app.services'])
    .run(function($ionicPlatform) {
        $ionicPlatform.ready(function() {
           captuvo.registerScannerCallback(function(barcode) {...}

I'm no Angular (or even js) pro, so I'm sure its something fundamental I am just not doing.

@alanlampa
Copy link
Contributor

alanlampa commented Oct 3, 2016

Hey Travis, I haven't tried it this way but you may try using $window:

angular.module('app.controllers', [])
    .controller('homeCtrl', ['$scope',  '$stateParams', '$window', 
    function($scope, $stateParams, $window) {

               $window.captuvo.registerScannerCallback(function(barcode) {
               Logger.log("Scanned: " + barcode);

            }
        }
    ])

Looking at it again though, I think your controller is getting initialized before ionicPlatform is ready.

@mxmissile
Copy link
Author

Yes, your right.

I'm curious, how, when and where is the "captuvo" object referenced? I'm not including CaptuvoCDV.js into my html anywhere, so I'm wondering how that happens,

@alanlampa
Copy link
Contributor

Cordova takes care of that for you at startup when you added the plugin, and loads into the window object. This is why you have to wait for the $ionicPlatform.ready event to make sure that cordova/ionic has had a chance to load it before it is used.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants