Is routerLink
properly placed in the view?
<p><a routerLink="/registration" class="nav-link">Register</a></p>
Checking my app.module
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { Routes, RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { AppComponent } from './components/app.component';
import { TestStartComponent } from './components/test-start.component';
import { TestListComponent } from './components/test-list.component';
import { RegistrationComponent } from './components/registration.component';
const appRoutes: Routes = [
{ path: '', component: TestListComponent },
{ path: 'teststart/:id', component: TestStartComponent },
{ path: '**', redirectTo: '/' },
{ path: 'registration', component: RegistrationComponent}
];
@NgModule({
imports: [BrowserModule, [CommonModule], FormsModule, HttpClientModule, RouterModule.forRoot(appRoutes)],
declarations: [AppComponent, TestListComponent, TestStartComponent, RegistrationComponent],
bootstrap: [AppComponent]
})
Details about my RegistrationComponent
import { Component, OnInit } from '@angular/core';
import { UserService } from '../services/user.service';
import { User } from '../models/user';
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { first } from 'rxjs/operators';
@Component({
templateUrl: '../views/registration.component.html',
providers: [UserService]
})
export class RegistrationComponent implements OnInit {
constructor(
private userService: UserService
) { }
ngOnInit() {
console.log("Initial method called");
}
Describing registration.component.html
<p>Initial method called</p>
No response when clicking the link. Other routerLinks are functioning correctly.