Angular Dart - 从父路线检索param

时间:2018-05-16 09:57:56

标签: angular dart

在模板中,我有以下routerLink: SELECT a.*, b.type FROM [testing].[PICKDETAIL] a left join [testing].[ORDERS] b on a.ORDERKEY = b.ORDERKEY left join [testing].[LOC] c on A.LOC = c.LOC left join [testing].[CODELKUP] d on c.ZCOORD = d.CODE WHERE a.STATUS = 0 AND b.[TYPE] = 'RT-B'

路由没问题,但我无法在mySubObjectsList组件中获取参数值[routerLink]="['../myObjects', {'id': object.id}, 'mySubObjectsList']"id是空的。

我想这是因为参数设置为我的父路由组件_routeParams.params

有没有办法在我的子组件中获取它?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我认为没有一种简单的方法。 您可以将params添加到父级中的服务,并将该服务提供给子级:

@Service()
class ParentRouteParams {
  Map<String,String> params;
  // using a StreamController is probably a good idea
}

@Component(
  selector: 'parent',
  providers: const [ParentRouteParams],
  ...
)
class Parent {
  Parent(this._parentRouteParams);

  final ParentRouteParams _parentRouteParams;

  @override
  void onActivate(_, RouterState current) {
    _parentRouteParams.params = current.parameters;
  }
}
@Component(
  selector: 'child'
  ...
)
class Child {
  Parent(this._parentRouteParams);

  final ParentRouteParams _parentRouteParams;

}