Reputation: 1445
If a parent component pass a property to a child component through @Input
decorator, it's passed by value, not by reference. If inside the child component I want to change the parent's property passed by @Input
, I have to emit the new value through an @Output
decorator, which we'll be captured by the parent component and assigned to the parent's property.
Is it possible to pass a property through an @Input
decorator by reference in Angular 2?
Regards,
Bernardo
Upvotes: 3
Views: 1886
Reputation: 39278
Just pass an object
to the @Input
. That will pass it as a reference.
If you change one of the properties on the object it will update referenced data.
example:
{name:'Joe'}
If the child updates the name
property it will be seen by the parent.
Upvotes: 2