Related Question
But this is not exactly the same.
I have two components. One component has the input, another component has a button. Now I want to populate some text on click of the button in the input field which is rendered by a different component.
input.component.html
<input #input type="text-area"/>
button.component.html
<li (click)="addText($event)">Click Me !!</li>
button.component.ts
@ViewChild('input') private input; addText(event){
console.log(this.input); //this is undefined
}
Project Structure :
- ./input/input.component.ts
- ./input/input.component.html
- ./button/button.component.ts
- ./button/button.component.html
I know I can use a service and then have an observable to listen to and subscribe to that for identifying the changes, but I just wanted to avoid that, as the accepted answer in the hyperlink above looked simpler.