在Angular 2 firebase中注销后重定向?

时间:2017-06-03 08:43:45

标签: javascript angular firebase

在logout()函数中,它不会导航到'add-listing' 显示ERROR TypeError:无法读取undefined的属性'navigate'? 请帮忙

这是我的component.ts

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app'
import {Router} from "@angular/router";

@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
    router: any;
  user: Observable<firebase.User>;

  constructor(public afAuth: AngularFireAuth) { 
     this.user = afAuth.authState;
  }

  ngOnInit() {
  }
  login(){
    this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
  }
  logout(){
    debugger;
    this.afAuth.auth.signOut();
    this.router.navigate(['/add-listing']);
    console.log(this.afAuth);
  }

}

0 个答案:

没有答案