I am currently working on implementing login functionality using Angular and Firebase. My goal is to receive the login result as an observable from my Auth service in the login component. However, I am encountering a specific error which is displayed below:
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.
Below is the TypeScript file for my login component:
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)
);
}
Here's my authentication service TypeScript file:
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)
);
}
}