0

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

<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 有可能吗?如果是,那怎么办?

4

2 回答 2

1

试试这样:

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

{ path: '/' + settings, component: `${Settings}`, name: `${SettingStudent}` }
于 2015-11-20T12:46:10.667 回答
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>
于 2016-06-13T14:05:16.163 回答