简体   繁体   English

Angular 6 - 材料表 - 获取选定的行值

[英]Angular 6 - Material Table - Get selected row values

Am trying to pass selected row value from one component to another on the button click.我试图在单击按钮时将选定的行值从一个组件传递到另一个组件。 but in this, example , from where can get selected row values and pass the selected value on button click?但是在这个例子中,从哪里可以获取选定的行值并在单击按钮时传递选定的值? followed by that routing will happen然后路由将发生

this.selection.selected returns the same object multiple time. this.selection.selected返回同一个对象。 how to stop that.如何阻止它。 i want to pass the value like我想传递这样的值

    <button (click)='onSelect(row)'>select row </button>

    onSelect(id){
    this.selectedRowValue = id
        //some logics
    }

could someone tell me how to pass the selected row value from one component to another?有人能告诉我如何将选定的行值从一个组件传递到另一个组件吗?

If you add this code in your component, selectedElements object changes with every selection change event如果您在组件中添加此代码,则selectedElements对象会随着每个选择更改事件而更改

  selectedElements: PeriodicElement[] = [];

  constructor(){
    this.selection.changed.asObservable().subscribe(a => this.selectedElements = [...this.selection.selected]);
  }

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

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