如果有人可以幫助我,這將是非常感激。 firebase
功能無法使用路由器。如何在火力點功能內使用路由器對象?
import { Component, OnInit } from '@angular/core';
import { FirebaseService } from '../../services/firebase.service';
import * as firebase from 'firebase';
import { Router } from '@angular/router';
@Component({
selector: 'app-listings',
templateUrl: './listings.component.html',
styleUrls: ['./listings.component.css']
})
export class ListingsComponent implements OnInit {
listings: any;
constructor(
private firebaseService: FirebaseService,
public router: Router
) {
這是firebase
功能,我無法使用路由器。
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
console.log('loggedIn');
} else {
// No user is signed in.
console.log('not loggedIn');
控制檯似乎也正常工作。
this.router.navigate(['/']);
}
});
}
ngOnInit() {
this.firebaseService.getListings().subscribe(listings => {
this.listings = listings;
console.log(listings);
});
}
}
有什麼特別的原因,你正在使用的火力地堡SDK,而不是AngularFire的[鑑別](https://github.com/angular/angularfire2/blob /master/docs/5-user-authentication.md)? –