首页 > 解决方案 > 如何使用角度将对象数组从一个页面传递到另一个页面

问题描述

有人可以帮我知道如何使用按钮单击路由从第一页到第二页发送对象数组,这是我的数组结构:

​Array[{ attributeName: "name0", attributeValue: "val0" }
      ​{ attributeName: "name1", attributeValue: "val1" }
​      { attributeName: "name2", attributeValue: "val2" }]

标签: angular

解决方案


通过路由传递对象是非常有限的。使用服务是更好的选择。您可以将说DataService类创建为角度服务,并通过依赖注入将其传递给您的应用程序。您可以通过 DI 将相关数据附加到DataService注入并在其他页面的组件中检索它。

请参阅https://angular.io/guide/component-interaction#!#bidirectional-service以及


推荐阅读