angular - 如何使用带有命名路由器出口的可变路由?
问题描述
我有一个键值对。该对的值是一条路线。我正在使用一个命名的 router-outlet。我找不到正确的语法。任何帮助表示赞赏。
.ts:
public myPair: { [key: string]: string } =
{
'Keyvalue': 'MyRoutHere'
};
.html:
<div *ngFor="let item of myPair | keyvalue">
<button mat-raised-button type="submit" color="accent" [routerLink]="item.value">{{item.key}}</button>
</div>
<router-outlet name="namedRoute"></router-outlet>
模块.routes.ts
const routes: Routes = [{
path: 'example', component: ExampleMainComponent, children: [
{ path: 'key-value', component: KeyValueComponent, outlet: 'namedRoute' }
]
}];
我尝试过的事情:
'Keyvalue': '[\'/examples\', {outlets: {\'definition\': [\'key-value\']}}]'
'Keyvalue': '(definition:key-value)'
'Keyvalue': '\\key-value'
我得到的错误:
URL 段:'examples/%5B'/examples',%20%7Boutlets:%20%7B'definition':%20%5B'key-value'%5D%7D%7D%5D' 错误:无法匹配任何路由. URL 段: 'examples/%5B'/examples',%20%7Boutlets:%20%7B'definition':%20%5B'key-value'%5D%7D%7D%5D'
'例子/%28定义:键值%29'
无法匹配任何路由。URL 段:“示例/键值”
解决方案
它未能读取您的对象,将您的 ts 和 html 更改为:
public myPair: { [key: string]: string } =
{
Keyvalue: 'MyRoutHere'
};
HTML:
<div *ngFor="let item of myPair | keyvalue">
<button mat-raised-button type="submit" color="accent" [routerLink]="item.value">{{item.key}}</button>
</div>
<router-outlet name="namedRoute"></router-outlet>
推荐阅读
- google-app-engine - 将 datastore_admin 映射到 Appengine 服务
- c# - 内容协商:如何删除 JSON 作为支持的格式?
- bash - bash 脚本,如何选择性地记录到日志文件和/或控制台
- android - 最快的服务器客户端通信?
- python - "from pylab import *" 返回 NoneType 对象不可迭代
- css - 将 FlexSlider 导航栏正确定位在中心
- react-native - 在物理设备上运行 React Native APP 时出错
- python - python中'./path'和'path'之间的区别
- python - 如何将对象的引用传递给函数以供重用
- r - 如何使用 Shiny 实现基本统计?tapply 中的错误:参数必须具有相同的长度”