I have two nested components: grid-container
and grid-component
.
In grid-container
, the grid-component
is initialized as follows:
<grid [title]="'This is the grid title'" [data]="data"></grid>
Data is initialized. Using events, the updated data
in grid-component
can be obtained in grid-container
. Its obvious until here for me. However, what should we typically do in angular 2 to update data
in the nested component (grid-component
in this case) from the container component (grid-container
)?
More specifically, (or as an illustration) I need a function that adds an item in container component (grid-container
) which will be applied in data
in grid-component
ps: its not two-way data binding as in this question which also didn't work for this problem.
EDIT:
export class GridComponent{ //child component
@Input() data:any;
}
import { GridComponent } from 'somewhere';
export class GridContainer{ //parent component
data:any = [{/*an initialized object which is visible in child component*/}]
addItem(){
data.push({/*an item is added*/};
//PROBLEM IS THE NEWLY ADDED ITEM IS NOT VISIBLE IN GridComponent class.
}
}
Your question is not clear. Please provide example of your HTML. If you have Parent-Child relation, then it is 2 way databinding.
If you have 2 Siblings, then it is still 2 way databinding where Parent serves as Proxy:
Or you can use Service Sibling Component Communication