看看这个solution(angular2),我一直在尝试使用相同的功能在angular4中工作并且做得很短。我得到的错误是:
“Auth”
类型中不存在“订阅”属性以下是一些示例代码(不工作):
angularFire.ts(提供者):
import {Injectable} from "@angular/core";
import { Observable } from 'rxjs/Observable';
import { FirebaseObjectFactoryOpts } from "angularfire2/interfaces";
import { AngularFireDatabaseModule, AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Injectable()
export class AF {
public messages: FirebaseListObservable<any>;
public users: FirebaseListObservable<any>;
public displayName: string;
public email: string;
public user: Observable<firebase.User>;
constructor(private afAuth: AngularFireAuth, private db: AngularFireDatabase) {
this.afAuth.auth.subscribe(
(auth) => {
if (auth != null) {
this.user = db.list.object('users/' + auth.uid);
}
});
this.messages = db.list('messages');
this.users = db.list('users');
} ...
}