I encountered a similar issue to mine on Stack Overflow. However, despite following the steps provided in the solution, my implementation is still not working.
Here is the structure of my components:
- Dashboard
- ActionButton
- Milestone
- Table
- SupplierSearch
- Table
I attempted to pass the array selectedRows
from Table to Dashboard, and then to ActionButton using CustomEvent
and
elRef.nativeElement.dispatchEvent
. However, when I tried to log the data to see if it was successfully passed to any parent component (Dashboard or Milestone) from Dashboard/Milestone/Table, the array did not get passed.
Please note that my code might be messy at the moment because I have been trying to fix this issue for almost a day and have experimented with various solutions. Kindly focus on the way I tried to implement the mentioned solution (CustomEvent
and
elRef.nativeElement.dispatchEvent
).
I am truly grateful for the knowledge shared by the Stack Overflow community, so please do not downvote this post if my English is poor or if there are inherent flaws in my problem statement.
Table
import {
Component,
ElementRef,
EventEmitter,
Input,
Output,
TemplateRef,
} from '@angular/core';
import { TableColumnHeader } from './models/table-column-header';
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.scss'],
})
export class TableComponent {
@Input() rowData;
@Input() headers: TableColumnHeader[] = [];
@Input() columnTemplate: TemplateRef<any>;
@Input() loading: boolean = false;
@Output() selectedRowsEvent = new EventEmitter<any[]>();
selectedRows = [];
constructor(private elRef: ElementRef) {}
// Rest of the TableComponent JavaScript code...
Milestone
// Milestone component JavaScript code...
Dashboard
// Dashboard component JavaScript code...
ActionButton
// ActionButton component JavaScript code...