が、私はそれが可能に提供するサービスとURLが対象にバインドされfirebaseオブジェクトを持っているかどうかを知りたかった、これは私の現在の設定です Queryオブジェクト
@Injectable()
export class HomieService {
homies: FirebaseListObservable<Homie[]>;
homie: FirebaseObjectObservable<Homie>;
public subject: BehaviorSubject<any>;
constructor(db: AngularFireDatabase) {
this.subject = new BehaviorSubject('');
this.homies = db.list('/homies');
this.homie = db.object('/homies/' + this.subject.value);
}
}
これは、URLをサブジェクトにバインドしたオブジェクトを「提供する」サービスです。 「選択」私は
を取得したいオブジェクトのキーである相棒 - list.component
selectHomie(selected: any) {
this.homieService.subject.next(selected);
this.router.navigateByUrl('/dashboard/homies/list/detail');
}
:
は、今のところ私はこのないコンポーネントを持っています
そして、このコードを持つ別のコンポーネント(ルータのためにロードするコンポーネント):
相棒 - detail.componentexport class HomieDetailComponent implements OnInit {
homie: any;
constructor(private homieService: HomieService, private serviceService: ServiceService, private router: Router) {
this.homieService = homieService;
}
ngOnInit() {
this.homie = this.homieService.homie;
}
}
は今何も起こりませんが、そのちょうど空のオブジェクトをthis.homie。件名やBehaviorSubjectを使用して(これは何もしない)
this.homieService.homie.subscribe(res => {
this.homie = res;
});
:ホーム-detail.componentにthis.homieを購読追加
:
は、私のような多くのバリエーションを試してみました(値なし):
public subject: Subject<any>;
constructor(db: AngularFireDatabase) {
this.subject = new Subject('');
this.homie = db.object('/homies/' + this.subject);
}
}
または
this.homie = db.object('/homies/' + this.subject);
しかし、これらの2つは、オブジェクトがオブジェクトであるため動作しません。