我正在尝试使用Angular和Firebase创建登录功能,从登录组件的Auth服务中可以观察到登录的结果。以下是我遇到的错误。
ERROR in src/app/login/login.component.ts:28:6 - error ng6002: appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
这是我的登录组件TS文件:
import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';
import { AuthService } from '../services/auth/auth.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
public form: FormGroup;
constructor(private formBuilder: FormBuilder, private authService: AuthService, private router: Router) {
this.form = this.formBuilder.group( {
email: ['', Validators.required],
password: ['', Validators.required]
});
}
ngOnInit(): void {
}
login() {
const inputValue = this.form.value;
console.log(inputValue.email, inputValue.password);
this.authService.login(inputValue.email, inputValue.password)
.subscribe(
success => this.router.navigate(['/user/home']),
error => alert(error)
);
}
这是我的身份验证服务ts文件:
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { from as fromPromise, Observable} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(private afauth: AngularFireAuth) {
}
login(email, password): Observable<any> {
return Observable.fromPromise(
this.afauth.signInWithEmailAndPassword(email, password)
);
}
}
显然,您错误地将LoginComponent放在了声明的@NgModule
的imports数组中。将其移到声明数组。
@NgModule({
imports: [/*LoginComponent*/], // <= move it from here
declarations: [LoginCompoennt] // <= to here
...
})
export class AppModule {}