Skip to content

Commit

Permalink
fix(in-app-browser): fix on method
Browse files Browse the repository at this point in the history
closes #1446
  • Loading branch information
ihadeed committed May 17, 2017
1 parent d68618f commit 975a65d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/@ionic-native/plugins/in-app-browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { Plugin, CordovaInstance, IonicNativePlugin } from '@ionic-native/core';
import { Plugin, CordovaInstance, InstanceCheck, IonicNativePlugin } from '@ionic-native/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromEvent';
import { Observer } from 'rxjs/Observer';

declare const cordova: Cordova & { InAppBrowser: any; };

Expand Down Expand Up @@ -141,8 +141,12 @@ export class InAppBrowserObject {
* @param event {string} Name of the event
* @returns {Observable<InAppBrowserEvent>} Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe.
*/
@InstanceCheck()
on(event: string): Observable<InAppBrowserEvent> {
return Observable.fromEvent(this._objectInstance, event);
return new Observable<InAppBrowserEvent>((observer: Observer<InAppBrowserEvent>) => {
this._objectInstance.addEventListener(event, observer.next.bind(observer));
return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer));
});
}
}

Expand Down

0 comments on commit 975a65d

Please sign in to comment.