I don't know how to use ViewChild feature in my Angular 17 project.
What i'm trying to do is to reload a component when using a function from another component:
Imagine having Component A and Component B and those two are in the same page in two different Mat-Tabs and are called #componentTemplateA and #componentTemplateB.
I have this function in Component A:
activityClicked(event: MatCheckboxChange, activity: ActivityDTO) {
this.activityService
.changeStatusActivityByCompany(
this.currentUser.FK_Company,
activity.ID,
event.checked
)
.subscribe({
next: (res) => {
this.getActivitiesByCompany();
},
error: (err) => {
DialogService.Error(err.message);
},
});
I'm trying to reload my Component B when clicking on the activityClicked function. That's because in Component A i select some elements through checking the checkbox and what i wish is to instantly have the Component B populated with the elements selected from Component A.
As now it only works if i reload the page after i used the activityChecked function but i want to get instantly updated once i check something.
@Jany, mat-tab works using "*ngIf" so when one component is visible, the other is not. Tihs is the reason you need "store" the values in some that exists always: a variable in a service or a variable in the component who have the mat-table.
If you pass a complex object to your components using an
@Input, you share this object.A simple example:
Or you can also use a service with a variable and in ngOnInit of the components equal the variable