angular - 如何使用角度将对象数组从一个页面传递到另一个页面
问题描述
有人可以帮我知道如何使用按钮单击路由从第一页到第二页发送对象数组,这是我的数组结构:
Array[{ attributeName: "name0", attributeValue: "val0" }
{ attributeName: "name1", attributeValue: "val1" }
{ attributeName: "name2", attributeValue: "val2" }]
解决方案
通过路由传递对象是非常有限的。使用服务是更好的选择。您可以将说DataService
类创建为角度服务,并通过依赖注入将其传递给您的应用程序。您可以通过 DI 将相关数据附加到DataService
注入并在其他页面的组件中检索它。
请参阅https://angular.io/guide/component-interaction#!#bidirectional-service以及
推荐阅读
- java - 为什么使用 super : public TreeSet(Comparator 比较器)
- python - 当我单击停止按钮时,vscode 不会关闭所有 django(python) 进程
- image - 在 Raspberry Pi 上使用 open62541 服务器运行 docker 容器
- ios - 如何知道数组计数是否在 didUpdateLocations Swift 中增加
- macos - Visual Studio For Mac 无法使用 Nuget 包管理扩展运行 Powershell
- html - 如何使用css在文本左侧添加加载器
- angular - 如何在侧导航的菜单下制作子菜单?
- jmeter - 在我们从 Jmeter 中的服务器获得完整响应之前,是否有任何响应?
- iot - 外部 MQTT 服务器订阅
- python - 在 Pandas 列中寻找与负值匹配的正值