Closed
Description
I use nativescript 8.2.3 with angular and with firebase-database the off function to unsubscribe of events does not seem not work.
listenerWrappers: any[] = [];
EventListener(onValueEvent: any, path: string): any {
const listener = firebase().database().ref(path).on('value', onValueEvent);
this.listenerWrappers.push({ listener: listener, path: path });
}
RemoveListeners(path: string) {
var listenerWrapper = this.listenerWrappers.filter(l => l.path == path)[0];
if (listenerWrapper) {
firebase().database().ref(path).off('value', listenerWrapper.listener)
this.listenerWrappers.splice(this.listenerWrappers.indexOf(listenerWrapper), 1);
}
}
Here how my code looks like. I call the RemoveListeners in my ngOnDestroy function of my component, I have no errors but the event is still attached as I still get log from my callback function.
package.json
{
"name": "TinaAppV2",
"main": "./src/main.ts",
"version": "1.0.0",
"private": true,
"dependencies": {
"@angular/animations": "~13.2.0",
"@angular/common": "~13.2.0",
"@angular/compiler": "~13.2.0",
"@angular/core": "~13.2.0",
"@angular/forms": "~13.2.0",
"@angular/platform-browser": "~13.2.0",
"@angular/platform-browser-dynamic": "~13.2.0",
"@angular/router": "~13.2.0",
"@nativescript-community/ui-material-floatingactionbutton": "^7.0.25",
"@nativescript-community/ui-material-tabs": "^7.0.25",
"@nativescript-community/ui-pulltorefresh": "^2.5.1",
"@nativescript/angular": "^13.0.0",
"@nativescript/core": "~8.2.2",
"@nativescript/datetimepicker": "^2.1.9",
"@nativescript/firebase-core": "^2.2.3",
"@nativescript/firebase-crashlytics": "^2.2.3",
"@nativescript/firebase-database": "^2.2.3",
"@nativescript/firebase-messaging": "^2.2.3",
"@nativescript/firebase-messaging-core": "^2.2.3",
"@nativescript/geolocation": "^8.0.2",
"@nativescript/iqkeyboardmanager": "^2.0.0",
"@nativescript/mlkit-barcode-scanning": "^1.0.5",
"@nativescript/mlkit-core": "^1.0.5",
"@nativescript/theme": "~3.0.2",
"nativescript-forgm-sound": "^1.1.3",
"nativescript-ui-chart": "^9.0.2",
"nativescript-ui-sidedrawer": "^10.0.2",
"rxjs": "~7.5.0",
"zone.js": "~0.11.5"
},
"devDependencies": {
"@angular-devkit/build-angular": "^13.3.6",
"@angular/compiler-cli": "~13.2.0",
"@nativescript/android": "8.2.2",
"@nativescript/ios": "8.2.3",
"@nativescript/types": "~8.2.0",
"@nativescript/webpack": "~5.0.6",
"@ngtools/webpack": "~13.2.0",
"typescript": "~4.5.5"
}
}