簡體   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