Angular2动态路由提供程序

时间:2015-11-19 07:03:09

标签: angular angular2-routing

我想提供[router-link],路径,组件和动态的值。

<li><a [routerLink]="['/SettingStudent']">Settings</a></li>

{ path: '/settings', component:Settings, name:'SettingStudent' }

在这个例子中我提供静态值,但是如何动态提供如下?

<li><a [routerLink]="['/{{SettingStudent}}']">{{Settings}}</a></li>

{ path: '/{{settings}}', component:{{Settings}}, name:'{{SettingStudent}}' }

有可能在angular2?如果是,那怎么样?

2 个答案:

答案 0 :(得分:1)

试试这样:

<li><a [routerLink]="['/' + SettingStudent]">{{Settings}}</a></li>

{ path: '/' + settings, component: `${Settings}`, name: `${SettingStudent}` }

答案 1 :(得分:0)

在课堂上,声明变量:

private routes: any[] = [
    {
        name: 'Asset Tag',
        path: ['SysInfoAssetTag']
    },
    {
        name: 'System',
        path: ['SysInfoSystem']
    }
]

然后在视图中

<ul>
    <li *ngFor="let route of routes"><a [routerLink]="route.path">{{route.name}}</a> </li>
</ul>