我想取消订阅我的Firebase数据库中某个位置的订阅。我正在使用Ionic 3和AngularFire2。如何取消订阅AngularFire数据库观察/订阅?
但是,我不知道什么样的数据类型,使我的订阅,因为截至目前这是一个FirebaseObjectObservable<any>
这是我不能退订。
没有退订,我打了以下错误,每当我尝试登录了(当我打电话afAuth.auth.signOut()
):
Runtime Error**
permission_denied at /parents/<auth.uid>: Client doesn't have permission to access the desired data.
Stack**
Error: permission_denied at /parents/<auth.uid>: Client doesn't have permission to access the desired data.
at G (http://localhost:8100/build/main.js:36366:36)
at Object.G (http://localhost:8100/build/main.js:36370:86)
at Lg (http://localhost:8100/build/main.js:36342:98)
at Ag.g.wd (http://localhost:8100/build/main.js:36335:310)
at og.wd (http://localhost:8100/build/main.js:36325:364)
at Yf.Xf (http://localhost:8100/build/main.js:36323:281)
at ag (http://localhost:8100/build/main.js:36307:464)
at WebSocket.Ia.onmessage (http://localhost:8100/build/main.js:36306:245)
at WebSocket.o [as __zone_symbol___onmessage] (http://localhost:8100/build/polyfills.js:2:24340)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967)
,因为它仍试图读的东西,现在不能访问,因为我”没有认证。
我的火力地堡规则:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
我home.ts文件:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFireDatabase, FirebaseObjectObservable, FirebaseListObservable } from 'angularfire2/database';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
//What datatype should I make this?
profileResult: FirebaseObjectObservable<any>;
constructor(public navCtrl: NavController,
private db: AngularFireDatabase,
private afAuth: AngularFireAuth) {
}
ngOnInit() {
//Get authentication state
this.afAuth.authState.subscribe(
(auth) => {
//if authenticated, get profile information for db and display using profileResult
if (auth != null) {
this.db.object('/parents/' + auth.uid).subscribe(profileResult => {
this.profileResult = profileResult;
console.log(profileResult);
});
}
});
}
/* What I would like to do, but can't unsubscribe from FirebaseObjectObservable
ngOnDestroy() {
this.profileResult.unsubscribe();
}
*/
//calling this results in my error
signOut() {
this.afAuth.auth.signOut();
}
}
我home.html的文件:
<ion-header>
<ion-navbar>
<ion-title>
My Awesome App
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
{{ profileResult?.firstName }}<br />
{{ profileResult?.lastName }}<br />
{{ profileResult?.youngestChildAge }}<br />
{{ profileResult?.interests }}<br />
{{ profileResult?.facebookUrl }}<br />
<button full ion-button (click)="signOut()">Sign Out</button>
</ion-content>
什么可以改变我profileResult: FirebaseObjectObservable<any>;
进入为了既捕获数据,又能够退订?