Reputation: 86730
i want to provide value of [router-link],path,component,and as dynamically.
<li><a [routerLink]="['/SettingStudent']">Settings</a></li>
{ path: '/settings', component:Settings, name:'SettingStudent' }
in this example i provide static values but how to provide dynamically like following ?
<li><a [routerLink]="['/{{SettingStudent}}']">{{Settings}}</a></li>
{ path: '/{{settings}}', component:{{Settings}}, name:'{{SettingStudent}}' }
is it possible in angular2 ? if yes then how ?
Upvotes: 0
Views: 1777
Reputation: 2945
In class, declare variable:
private routes: any[] = [
{
name: 'Asset Tag',
path: ['SysInfoAssetTag']
},
{
name: 'System',
path: ['SysInfoSystem']
}
]
Then in view
<ul>
<li *ngFor="let route of routes"><a [routerLink]="route.path">{{route.name}}</a> </li>
</ul>
Upvotes: 0
Reputation: 51
Try it like this:
<li><a [routerLink]="['/' + SettingStudent]">{{Settings}}</a></li>
{ path: '/' + settings, component: `${Settings}`, name: `${SettingStudent}` }
Upvotes: 1