繁体   English   中英

如何以角度从另一个组件传递对象?

[英]How can i pass object one component from another component in angular?

我有两个组件DialogOverviewExample和DialogOverviewExampleDialog。 我在DialogOverviewExample中有“元素”对象,我想将此元素传递给DialogOverviewExampleDialog,我该如何传递它

DialogOverviewExample组件中的以下对象存储

Element = [
  {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
  {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
  {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
  {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}

];

我希望将其打印在DialogOverviewExample组件上

项目

检查上面的链接以获取我的组件代码。帮助我

在您的openDialog函数上,不是只是将Element传递给data吗?

data: this.Element

还是我在您的问题中遗漏了一些细节?

如果您还希望传递代码中包含的其他详细信息,它将类似于

data: { element: this.Element, name: this.name, animal: this.animal }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM