Upon logging into the Angular app with the ASP.NET Core API app, I encountered the following error message:
Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[AuthGuard]: StaticInjectorError(Platform: core)[AuthGuard]: NullInjectorError: No provider for AuthGuard!
login.component.ts
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { routerTransition } from '../router.animations';
import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
import { first } from 'rxjs/operators';
import { AlertService, AuthenticationService } from '../_services';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
animations: [routerTransition()]
})
export class LoginComponent implements OnInit {
loginForm: FormGroup;
loading = false;
submitted = false;
returnUrl: string;
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private authenticationService: AuthenticationService,
private alertService: AlertService) {}
ngOnInit() {
this.loginForm = this.formBuilder.group({
username: ['', Validators.required],
password: ['', Validators.required]
});
// reset login status
this.authenticationService.logout();
// get return url from route parameters or default to '/'
...
<p>AuthenticationService.ts</p>
...
<p>EmployeeController</p>
...
<p>app.module.ts</p>
...
<p>auth.guard.ts</p>
...