angular-cli を使用して angularfire2 アプリケーションを構築しています。
最初の子サブルートのロード時に、angularfire2 がコンソールにエラーをスローするという問題があります。
error_handler.js:47 EXCEPTION: Uncaught (in promise): TypeError: 未定義のプロパティ 'subscribe' を読み取れません
これは、ページが「更新」されたときに発生します。コンポーネントから離れて更新後に戻ると、データは正常に読み込まれ、エラーは発生しません。これが Angular2 や AngularFire2 のバグなのか、それとも私が何か間違っているのかはわかりません。誰かがこの問題を抱えていますか?関連するコンポーネントコードは次のとおりです。
import {Component, OnInit, ViewChild, OnDestroy}from '@angular/core';
import {Router} from '@angular/router';
import {AngularFire, FirebaseListObservable, AngularFireModule} from 'angularfire2';
@Component({
selector: 'app-users',
templateUrl: 'users.component.html',
styleUrls: ['users.component.scss', '../shared/styles/dashboard.scss']
})
export class EmployeesComponent implements OnInit, OnDestroy {
private groupKey: string;
private groupAdmin: string;
private user: any;
private _auth: any;
private positions: FirebaseListObservable < any > ;
private users: FirebaseListObservable < any > ;
constructor(private af: AngularFire, private router: Router) {}
ngOnInit() {
this.af.auth.subscribe(auth => {
this._auth = auth;
let currentUser = this.af.database.object('/Users/' + this._auth.uid).take(1).subscribe(user => {
this.groupKey = user.group;
this.users = this.af.database.list('/Users', {
query: {
orderByChild: 'group',
equalTo: this.groupKey
}
});
this.positions = this.af.database.list('/Groups/' + this.groupKey + '/Positions');
this.af.database.object('/Groups/' + this.groupKey + '/admin').take(1).subscribe(group => {
this.groupAdmin = group.admin;
});
});
});
}
ngOnDestroy() {
this.users.subscribe().unsubscribe();
this.positions.subscribe().unsubscribe();
}
}