选择特定行时如何将数据获取到另一个组件
当我在此处使用Mat-able选择特定行时,我正在尝试获取数据,
这是我要做什么的示例,通过获得DR20220000013将传递到交付收据#
.html
<mat-table [dataSource]="DeliveryReceipt">
<ng-container matColumnDef="transactionType">
<mat-header-cell *matHeaderCellDef>Transaction #</mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.transactionType}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"
(click)="selectedRow(row)"></mat-row>
</mat-table>
.ts
selectedRow(row){
console.log('selectedRow', row)
}
I'm trying to get the data when i'm selecting specific row using mat-table
Here the example of what i'm going to do, by getting DR20220000013 will pass to the Delivery Receipt#
.HTML
<mat-table [dataSource]="DeliveryReceipt">
<ng-container matColumnDef="transactionType">
<mat-header-cell *matHeaderCellDef>Transaction #</mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.transactionType}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"
(click)="selectedRow(row)"></mat-row>
</mat-table>
.TS
selectedRow(row){
console.log('selectedRow', row)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在组件之间共享数据的许多方法,输入绑定,服务您命名... https:// angular。 io/guide/inputs-utputs
,但是我在这里围绕着一个肢体,猜测有什么用。上覆的
Mat-table
选择该行似乎是对话模式。模式可能是从父组件中开放的,很可能是
交付收据#
也是吗?因此,当我们打开模式时,我们将订阅模式。当模态关闭时,我们将开始聆听模态发出的值(即当用户do
selectedrow()
我们关闭模态并返回值时)。然后将返回值捕获并馈送到交货收据#
。父级中
在模式中的
:以上是一个解释,如何从模态返回数据,然后使用打开的返回数据,您可能必须更改先前的代码才能在项目中实际工作。
Many ways to share data between components, input binding, services you name it... https://angular.io/guide/inputs-outputs
But I'm going out on a limb here and taking a guess what could work. The overlying
mat-table
where you select the row appears to be a dialog modal.The modal is probably opened somewhere from the parent component, most likely where
Delivery Receipt#
is too?So when we open the modal, we will subscribe to the modal. We will start listening to the value emitted by the modal when the modal closes (i.e when user does
selectedRow()
we close modal and return value). That return value is then catched and fed toDelivery Receipt#
.In parent
In the modal:
The above is an explanation how to return data from modal and then use return data where it was opened from, you may have to change the previous code for it to actually work in your project.
最简单的方法是使用共享服务
服务
与表
组件
Easiest way is to use a shared service
Service
Component with table
Any other component that needs the data