I've been trying to pass a string
from a child component to its parent component.
Child Component:
//imports...
@Component({
selector: 'child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css'],
providers: [ChildService]
})
export class DataTableComponent implements OnInit {
constructor(private http: HttpClient, private childService : ChildService) {}
myMap = new Map<string, ISomeInterface>();
currentSelection: string;
@Output() sendDataEvent = new EventEmitter<string>();
sendData() {
console.log("sending this data: " + this.myMap.get(this.currentSelection).name);
this.sendDataEvent.emit(this.myMap.get(this.currentSelection).name);
}
}
Parent Component:
html ->
<d-table (sendDataEvent)="receiveBusinessCycle(event)"></d-table>
typescript ->
//imports...
@Component({
selector: 'parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.css'],
providers: [ParentService]
})
export class MyParentComponent {
totoName: string;
constructor(private parentService : ParentService) { }
receiveBusinessCycle($event) {
console.log($event); //shows in console 'undefined'
console.log($event as string);
this.totoName = $event;
}
}
The problem is that I'm receiving an undefined event when trying to get the data in the parent component, here are the console logs:
sending this data: 201808
main.bundle.js:2328 undefined
main.bundle.js:2329 undefined
Any suggestions on how to solve this issue?