How to get AdMob Pro working in Ionic

I am getting 'AdMob' is undefined when I try to execute the code below. I am trying to use the Cordova AdMob Pro plugin, but can't get past the undefined error(s). I can't confirm if the plugin is even being loaded.

Here are the versions I'm using: AngularJS v1.3.4, Cordova v4.1.2, Ionic v1.2.8. I'm running the code on a Galaxy S5 phone running Android version 4.4.4.

I've tried adding this code in both the app.js and the controller.

$ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
        // org.apache.cordova.statusbar required
        StatusBar.styleDefault();
    }

    console.log('window.cordova.plugins: ' + window.cordova.plugins);  //returns object
    console.log('window.cordova.plugins.AdMob: ' + window.cordova.plugins.AdMob);  //returns undefined
    console.log('window.AdMob: ' + window.AdMob);    //returns undefined
    console.log('AdMob: ' + AdMob); //returns undefined
    console.log('window.AdmobAd: ' + window.AdmobAd); //returns undefined
    console.log('AdmobAd: ' + AdmobAd);  //returns undefined

    if (window.AdMob || AdMob) {
        alert('admob plugin found');
        var admob_key = (device.platform == "Android") ? "ADMOB_KEY" : "IOS_PUBLISHER_KEY";
        var admob = window.AdMob;
        admob.createBannerView(
            {
                'publisherId': admob_key,
                'adSize': admob.AD_SIZE.BANNER,
                'bannerAtTop': false
            },
            function () {
                admob.requestAd(
                    { 'isTesting': false },
                    function () {
                        admob.showAd(true);
                    },
                    function () { console.log('failed to request ad'); }
                );
            },
            function () { console.log('failed to create banner view'); }
        );
    }
});

Just went through this as well and found that the error is from trying to find 'AdMob' when that doesnt exist on if (window.AdMob || AdMob)

if you just use 'if (window.AdMob) {' you should be fine.

I just developed an AngularJS extension on top of AdMob Pro so you can interact better with this Cordova Plugin.

Here is the repository: https://github.com/santonocito/angular-admobpro

Here an example of how you can use it with Ionic:

angular.module('yourApp', ['ionic', 'admob'])
    .run(function($rootScope, $state, $log, $adMob) {

        $ionicPlatform.ready(function() {
            // AdMob
            if(window.AdMob) {
                var admobid;

                if (device.platform == "Android") {
                    admobid = { // for Android
                        banner: 'ca-app-pub-your-ad-key',
                        interstitial: 'ca-app-pub-your-ad-key'
                    };
                } else {
                    admobid = { // for iOS
                        banner: 'ca-app-pub-your-ad-key',
                        interstitial: 'ca-app-pub-your-ad-key'
                    };
                }

                $adMob.createBanner( {
                    adId: admobid.banner,
                    autoShow: true,
                    bgColor: 'black',
                    position: $adMob.position.BOTTOM_CENTER
                });

                $adMob.prepareInterstitial({
                    adId: admobid.interstitial,
                    autoShow: false
                });
            }
        });
    });