【发布时间】:2017-01-20 22:33:15
【问题描述】:
我想在 Angular 中创建一个详细信息页面,并希望通过 RouterLink 传递一个条目 ID。有没有办法获取url中的参数?
网址如下:http://localhost:8080/details?date=13-09-2016
【问题讨论】:
标签: angularjs angular dart angular2-routing
我想在 Angular 中创建一个详细信息页面,并希望通过 RouterLink 传递一个条目 ID。有没有办法获取url中的参数?
网址如下:http://localhost:8080/details?date=13-09-2016
【问题讨论】:
标签: angularjs angular dart angular2-routing
也可以使用RouteParams获取参数。您可以将其注入到您的组件中:
@Component(...)
class MyDetailsComponent {
final RouteParams _routeParams;
MyDetailsComponent(this._routeParams){
var date = _routeParams.get('date');
}
}
您可以找到更多详细信息here。
【讨论】:
实现OnActivate
@override
routerOnActivate(ComponentInstruction nextInstruction,
ComponentInstruction prevInstruction) {
String routeParamValue = nextInstruction.params['paramName'];
String queryParamValue = nextInstruction.urlParams['paramName'];
}
【讨论】:
params 更改为queryParams。 param 用于路由参数(path: '/some/:paramName/other')
@RouteConfig(const [ const Route(path: '/view', name: 'Home', component: SimpleKVComponent, useAsDefault: true), const Route(path: '/settings', name: 'Settings', component: SettingsComponent), const Route(path: '/details', name: 'Details', component: DetailsComponent) ])
<td><a [routerLink]="['/Details', { date: history['link'] }]"><i class="glyphicon glyphicon-eye-open"></i></a></td>
class DetailsComponent implements OnActivate {了吗?