简体   繁体   中英

Pass a value of text fields from one component to another component in angular 8

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM