Skip to content

Cordova first steps

Miquel Martín edited this page Jun 15, 2020 · 10 revisions

title: Cordova-Phonegap first steps description: First steps url: /cordova-first-steps contributors:

  • appfeel
  • bitgenoma
  • marcpascualsanchez
  • miqmago

First steps

When working on an android or ios device, keep in mind that the plugin will be available only after 'deviceready' event. The plugin is accessible from window object: window.admob.

The ad ids used in the example code are should be used only for development and test purposes. If you do not replace them with your own ones, please ensure to always use the isTest option set to true.

Javascript

async function onDeviceReady() {
    await admob.createBannerView({
        bannerAdId: 'ca-app-pub-3940256099942544/6300978111',
    });
}

document.addEventListener('deviceready', this.onDeviceReady, false);

Angular

import { Component, OnInit } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Admob } from '@ionic-native/admob';

@Component({
    selector: 'app-home',
    templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
    constructor(private admob: Admob, private platform: Platform) { }

    async ngOnInit() {
        await this.platform.ready();
        await this.admob.createBannerView({
            bannerAdId: 'ca-app-pub-3940256099942544/6300978111',
        });
    }
}

Angular is referring to Angular v2 version and newer. For AngularJS (Angular v1) see this example

Clone this wiki locally