I have a route registered with some data:
const routes: Routes =
[
{path: 'my-route', data: { title: 'MyTitle' }, component: MyComponent},
];
and I'm trying to access to the route's data using ActivatedRoute
:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({...})
export class MyComponent implements OnInit {
private routeData;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.routeData = this.route.data.subscribe((data) => {
console.log(data); // this is returning an empty object {}
});
}
}
but for some reasons data
is an empty object.
How to solve this problem?