While working on Angular2 routing, I encountered an issue where my dynamically generated links were causing an error after a few seconds. The error message is as follows:
https://i.sstatic.net/6GM06.png
Here is the code snippet for my routerLink:
<a [routerLink]="['category/', electronic.name]" *ngFor="let electronic of electronics ">
{{electronic.name}}
</a>
And here is the component code:
import { Component, OnInit } from '@angular/core';
import { DatabaseService } from "../../service/database.service";
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-category-list',
templateUrl: './category-list.component.html',
styleUrls: ['./category-list.component.css']
})
export class CategoryListComponent implements OnInit {
constructor(private database: DatabaseService, private activeRoute: ActivatedRoute) { }
ngOnInit() {
let name = this.activeRoute.snapshot['name'];
console.log(name);
}
}