Run function that within ionicplatform.ready in other controllers?


#1

Below is a working code running createAdmobBanner function. But how can I run the createAdmobBanner function in other controller?

angular.module(‘starter’, [‘ionic’, ‘starter.controllers’])

.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {

    var admobid = {};
    if (/(android)/i.test(navigator.userAgent)) {
        admobid = {
            banner: 'ca-app-pub-3815248714018431/123456789'
        };
    }
    function createAdmobBanner() {
        AdMob.createBanner({
            adId: admobid.banner
            adSize: 'SMART_BANNER',
            position: 8
        });
    }
    createAdmobBanner();
});

})

I got createAdmobBanner is not defined if I simply do createAdmobBanner() in my controllers. I tried $rootScope but the plugin doesn’t seem work with that.