I have in my parent component this:
obj: any = { row1: [], row2: [], total: [], sumTotal: 0 };
I pass obj to child component :
You should try using services to pass values from one component to another. https://www.youtube.com/watch?v=69VeYoKzL6I
Inside this child component i have another child component where i change values of array but its not changing on my parent object.
Data flow between parent and child components is not two-way in Angular. So the changes you make in a child component won't be reflected in the parent component.
You can use EventEmitter
to emit events from child component to parent component.
Child component:
In your child component, declare an EventEmitter
object.
@Output() updateObjDataEvent: EventEmitter<any> = new EventEmitter<any>();
Then use emit
method from anywhere in the child component to send data to parent component.
// Update parent component data.
this.updateObjDataEvent.emit(obj);
Parent component:
In your parent component template, subscribe to this event:
<app-child-component-selector (updateObjDataEvent)="updateObj($event)">
</app-child-component-selector>
Then in your parent component, create updateObj()
method to handle data updates from child component.
updateObj(data) {
// Do something.
}
In the updateObj()
method, you can update your parent component's array object.