如何安装uid 我的.ts文件是这样的,
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { Router } from "@angular/router";
@Component({
selector: 'app-candidate-login',
templateUrl: './candidate-login.component.html',
styleUrls: ['./candidate-login.component.css']
})
export class CandidateLoginComponent implements OnInit {
user: Observable<firebase.User>;
constructor(
public afAuth: AngularFireAuth,
private router: Router) {
this.user = afAuth.authState;
console.log(this.user.uid);
}
ngOnInit() {
}
login(){
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
this.router.navigate(['/registration']);
}
}
但是它显示了像
这样的错误C:/MyApp/Join/job-site/src/app/candidate-login/candidate-login.component.ts (23,26): Property 'uid' does not exist on type 'Observable<User>'.
如何解决这个问题?请帮帮我先生? 其实我想知道当前的用户?我想安慰它。帮助我吗?
答案 0 :(得分:0)
您必须像这样订阅afAuth.authState
this.afAuth.authState.subscribe(user => {
this.user = user;
console.log(this.user.uid);
});