Rituraj ratan Rituraj ratan - 8 days ago 6
AngularJS Question

How to get current route custom data in angular 2?

I have set up routes is like below

const appRoutes: Routes = [
{
path: 'login',
component: LoginComponent,
data: {
title: 'Login TTX'
}
},
{
path: 'list',
component: ListingComponent,
data: {
title: ' TTX Home Page',
module:'list'
}
},
{
path: '',
redirectTo: '/login',
pathMatch: 'full'
},
];


now when i come to
'/list'
route then on
'listing.component.ts'
i have written below code

export class ListingComponent {

public constructor(private router:Router) {
//here how i can get **data** of **list** routes

}
}

Answer
  public constructor(private route:ActivatedRoute, private router:Router) {
      console.log(route.snapshot.data['title']);
  }