在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);
}
}