Reputation: 25
So basically I have a component that I want to change its value, let's call him component A
. And I have a component which is a text field, let's call him component B
. How do I change the value of component A
to the value of component B
?
Upvotes: 0
Views: 43
Reputation: 60528
The idea of a component is that the component class manages and controls its own template. Another component should not attempt to modify another component's template.
If one component has information that the other component's template needs, the component should provide the information to the other component's class and let the component update its template.
How this is done depends on the relationship between the components. If there is a "parent/child" relationship where one component is nested within the other, then there are well-documented techniques for parent/child communication. See this: https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#sts=Parent%20and%20children%20communicate%20via%20a%20service
If the components are not related, consider using a service to share data between the components.
Upvotes: 1