I want to call a function (TagDataSubscriber.next) from a global scope JavaScript function. It's a bridge between Flutter app and my Ionic app. Any idea how to achieve that? I found a app-injector somewhere in the internet, but it won't work.
Regards, Markus
import {Injector} from '@angular/core';
let appInjectorRef: Injector;
export const AppInjector = (injector?: Injector): Injector => {
if (injector) {
appInjectorRef = injector;
}
return appInjectorRef;
};
Provider file:
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Subscriber} from 'rxjs/Subscriber';
import {AppInjector} from "../../app/app-injector";
/* function called by Flutter if a NFC tag was detected */
window["nfcTagReceived"] = function (nfcTag) {
let injector = AppInjector();
let nfcService = injector.get(NfcServiceProvider);
nfcService.TagDataSubscriber.next(nfcTag);
}
@Injectable()
export class NfcServiceProvider {
private nfcAvailable: boolean = false;
private tagDataSubscriber: Subscriber<any>;
private tagRead: Observable<number> = new Observable<number>(
observer => this.tagDataSubscriber = observer
);
public get TagDataSubscriber(): Subscriber<any> {
return this.tagDataSubscriber;
}
public get TagRead(): Observable<number> {
/*Uncomment*ReadNfcOnce.postMessage("");*Uncomment*/
return this.tagRead;
}
public get NfcAvailable(): boolean {
return this.nfcAvailable;
}
constructor() {
}
}