Last active
January 24, 2018 20:42
-
-
Save b-tiwari/7c29b8dac0bc3c605ef833ed6535fc14 to your computer and use it in GitHub Desktop.
Ionic Events - Subscribing to Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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