Im使用Angular 4和Firebase進行身份驗證。我收到錯誤「Property'auth'在類型'AngularFireModule'上不存在。」類型'AngularFireModule'上不存在屬性'auth'
的代碼如下
import { AngularFireModule} from 'angularfire2';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFireDatabaseModule } from 'angularfire2/database';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
animations: [moveIn()],
host: {'[@moveIn]': ''}
})
export class LoginComponent implements OnInit {
error: any;
constructor(public af: AngularFireModule,private router: Router) {
this.af.auth.subscribe(auth => {
if(auth) {
this.router.navigateByUrl('/members');
}
});
loginFb() {
this.af.auth.login({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup,
}).then(
(success) => {
this.router.navigate(['/members']);
}).catch(
(err) => {
this.error = err;
})
}
}
版本信息: 「@角/路由器」: 「^ 4.0.0」,
"angularfire2": "^4.0.0-rc.1",
"core-js": "^2.4.1",
"firebase": "^4.1.3",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
UPDATE:
這個工作
constructor(public af: AngularFireAuth,private router: Router) {
this.af.authState.subscribe(auth => {
if(auth) {
this.router.navigateByUrl('/members');
}
@php_beginner是AngularFireAuth不AngularFireAuthModule :) – brijmcq
@php_beginner能行嗎? – brijmcq
是的,它的工作原理。謝謝 – sinthu225