I\'m trying to create a parent and child component where the child component is going to have a states drop down. Can someone help me understand how I can access the states
Using output and emit you can easily access child data in parent component. For example
import { Component,Input,Output,EventEmitter } from '@angular/core';
@Component({
selector: 'child-component',
template: ''
+'Child Component: '
+'{{name}}'
+''
+'',
styleUrls: ['./app.component.css']
})
export class ChildComponent {
@Input() name: string;
@Output() shareDataToParent = new EventEmitter();
title : string;
constructor(){
this.title = 'Sharing from child to parent';
}
shareData(){
this.shareDataToParent.emit(this.title);
}
}
Parent component
shareDataToParent(sharedText:string){
console.log(sharedText);
}
More info on child parent communication