Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Broadcaster

Improve this doc

This plugin adds exchanging events between native code and your app.

Repo: https://github.com/bsorrentino/cordova-broadcaster

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-broadcaster
    $ npm install --save @ionic-native/[email protected]
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Broadcaster } from '@ionic-native/broadcaster';

constructor(private broadcaster: Broadcaster) { }

...

// Listen to events from Native
this.broadcaster.addEventListener('eventName').subscribe((event) => console.log(event));

// Send event to Native
this.broadcaster.fireNativeEvent('eventName', {}).then(() => console.log('success'));

Instance Members

addEventListener(eventName)

This function listen to an event sent from the native code

Param Type Details
eventName string

Returns: Observable<any> Returns an observable to watch when an event is received

fireNativeEvent(eventName, eventData)

This function sends data to the native code

Param Type Details
eventName string
eventData any

Returns: Promise<any> Returns a promise that resolves when an event is successfully fired

API

Native

General