-4

I am getting value from document.getElementByid from text field. I want to transfer the value got from getElementByid to other component. Any one can guide me how to do that.

Example component A: get value using a=document.getElementByid pass this value to Component B: receive Value a from componentA. Thanks.

  • Please check documentation on component interaction https://angular.io/guide/component-interaction – ihor.eth Apr 08 '20 at 04:08
  • Does this answer your question? [How to pass data between two components in Angular 2](https://stackoverflow.com/questions/39325503/how-to-pass-data-between-two-components-in-angular-2) – ihor.eth Apr 08 '20 at 04:09

1 Answers1

1

If the other component is a child of the current component, you can listen to the input Event and update the value in the other component accordingly.

If the other component is not a child of the current component, you can use a singleton-service to pass the value to another component.

See https://stackblitz.com/edit/angular-tcgwkv for an example to both approaches.

Typing anything into the Main Component text box will update the values for both other components.

  • i want to communicate on the base of component level not with parent child relation. – Muhammad Ahsan Apr 08 '20 at 11:45
  • For Communication between components that are not in a parent child relation you can use a singleton-service (as shown in the stackblitz). –  Apr 08 '20 at 11:48