typescript - Add routes dynamically in angular 2 -
i want add path in routes dynamically. that. i'm getting empurl form class. on clicking specific function empurl changes value in class in this.router.navigate(["/admin:" + emp.empno])(admin.component.ts). here emp.empno returns 1 element i.e. employee1, employee2 etc. empurl access 1 element @ time. know can't in way. want make point clear.
here's router.component.ts
import { component, input } '@angular/core'; import { routermodule, routes } "@angular/router"; import { adminaccount } "../admin/admin.component"; import { employeecomponent } "../employee/employee.component"; export const routing: routes = [ { path: '', component: home }, { path: 'admin', component: adminaccount }, { path: 'admin:' + this.empurl, component: employeecomponent } ]; @component( { selector: "router", }) export class naviagtetoemp { @input() empurl; } here's admin.component.ts
navigateto(emp: emplogin) { for(let key in this.data) this.empurl[key] = this.data[key].empno; this.router.navigate(["/admin:" + emp.empno]); } here's admin.component.html
<router [empurl] = 'empurl.employee1'></router> here accessing 1 of element employee1.this employee1 not static. change value dynamically.
Comments
Post a Comment