Skip to content

Instantly share code, notes, and snippets.

@b-tiwari
Last active January 24, 2018 20:42
Show Gist options
  • Save b-tiwari/7c29b8dac0bc3c605ef833ed6535fc14 to your computer and use it in GitHub Desktop.
Save b-tiwari/7c29b8dac0bc3c605ef833ed6535fc14 to your computer and use it in GitHub Desktop.
Ionic Events - Subscribing to Event
import { Component } from '@angular/core';
import { Events, AlertController } from 'ionic-angular';
import { AppEventsEnum } from '../Enums/AppEvents';
@Component({
selector: 'subscriber',
templateUrl: 'subscriber.html'
})
export class Subscribe {
constructor(private events: Events, private alertCtrl: AlertController, ) {
this.subscribeToArticle();
}
subscribeToArticle = () => {
this.events.subscribe(AppEventsEnum.PublishArticle , (data) => {
const alert = this.alertCtrl.create({
title: 'New Article Published',
message: `Title: ${data.title}, Author: ${data.author}`
buttons: ['Dismiss']
});
alert.present();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment