AngularJS 2 Dart获取RouterLink参数

时间:2016-09-13 10:42:20

标签: angularjs angular dart angular2-routing

我想在Angular中创建一个详细信息页面,并希望通过RouterLink传递一个条目ID。有没有办法在网址中获取参数?

网址如下:http://localhost:8080/details?date=13-09-2016

2 个答案:

答案 0 :(得分:2)

此外,RouteParams可用于获取参数。您可以将它注入组件:

@Component(...)
class MyDetailsComponent {
  final RouteParams _routeParams;
  MyDetailsComponent(this._routeParams){
    var date = _routeParams.get('date');
  }
}

您可以找到更多详情here

答案 1 :(得分:1)

实施OnActivate

  @override
  routerOnActivate(ComponentInstruction nextInstruction,
      ComponentInstruction prevInstruction) {
    String routeParamValue = nextInstruction.params['paramName'];
    String queryParamValue = nextInstruction.urlParams['paramName'];
  }