flauc / angular2-notifications

A light and easy to use notifications library for Angular.
https://stackblitz.com/edit/angular2-notifications-example
MIT License
746 stars 164 forks source link

onClick redirect #167

Open pujan1 opened 7 years ago

pujan1 commented 7 years ago

Is there a function for this service where if a user clicks the push notification, then it redirects to some url ?

flauc commented 7 years ago

Hi @pujan1 ,

There isn't, but you can subscribe to the on emitter this.service.getChangeEmitter().subscribe, then when you receive a clean event just fire window.open().

Jayliu95 commented 7 years ago

@flauc Do you mind giving a quick example of what you meant ^^?

I was able to come up a hacky way as a workaround:

testPushNotify(){ console.log(this.toNotify); this._pushNotifications.create("Hello World", {body: 'Chicken Wings'}).subscribe( (res: any) => {console.log(res['notification']), res['notification']['onclick'] = this.event}, (err:any) => console.log(err) ); }

event(){ //Whatever you want to do once push notification is clicked -- window.open("http://localhost:3000/"); }