angular - Angular Dart - 从父路由中检索参数
问题描述
在模板中,我有以下 routerLink:
[routerLink]="['../myObjects', {'id': object.id}, 'mySubObjectsList']"
路由没问题,但我无法id
在 mySubObjectsList 组件中获取参数值。_routeParams.params
是空的。
我猜这是因为参数设置为我的父路由组件myObjects
。
有没有办法在我的子组件中获取它?
谢谢你的帮助。
解决方案
我不认为有一个简单的方法。您可以将参数添加到父服务中,并使该服务可供子服务使用:
@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;
}
推荐阅读
- xpath - 无法使用 xpath 编码匹配精确符号“&”“<”“>”
- javascript - 如何将 eval(ID) 从列表视图传递到 asp.net 上的模式弹出窗口
- python - 使用特定列将抓取的数据导出到 CSV
- netlogo - 在 NetLogo 中改变海龟变量的好方法是什么?
- angular - 如何解决使用自定义验证器语法遇到的错误?
- java - Java除法运算符没有给出预期的结果
- react-native - 如何使用 React Native 制作警报事件?
- python-3.x - 为什么会引发 http.client.IncompleteRead 异常?
- python - 视图中的问题,“学生”类没有“对象”成员pylint(无成员)?
- sql - Insert into 命令不插入任何内容,但 select 语句返回所需的所有元素