Angular: passe dados para o componente carregado via rota
import {ActivatedRoute, Data} from "@angular/router";
const routes: Routes = [
{path: 'developer', component: EmployeeComponent, data: {emp_type: 'developer'}},
{path: 'tester', component: EmployeeComponent, data: {emp_type: 'tester'}},
{path: 'analyst', component: EmployeeComponent, data: {emp_type: 'analyst'}}
];
class EmployeeComponent {
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.data_subscription = this.route
.data
.subscribe(data: Data =>
console.log('Employee type passed via route is ' + data.emp_type)
);
}
ngOnDestroy() {
this.data_subscription.unsubscribe();
}
}
amit.bhagat