Within my Angular-12 application, I have implemented two components: employee-detail and employee-edit.
In the employee-detail.component.ts file:
profileTemplate: boolean = false;
contactTemplate: boolean = false;
profileFunction() {
this.profileTemplate = true;
this.contactTemplate = false;
}
contactFunction() {
this.profileTemplate = false;
this.contactTemplate = true;
}
The corresponding employee-detail.component.html contains:
<div class="card-body">
<div id="external-events">
<button (click)="profileFunction()" type="button" class="btn btn-block btn-primary">Profile</button>
<button (click)="contactFunction()" type="button" class="btn btn-block btn-success">Contact</button>
</div>
</div>
<div *ngIf="profileTemplate" class="card card-default color-palette-box">
</div>
<div *ngIf="contactTemplate" class="card card-default color-palette-box">
</div>
By clicking on the buttons, either the profile or contact section is displayed based on the function triggered.
Now onto another component, which is employee-edit:
Within employee-edit.component.ts:
onSubmitProfile() {
this.router.navigate(['/employees-detail', this._id]);
}
onSubmitContact() {
this.router.navigate(['/employees-detail', this._id]);
}
I aim to achieve a functionality where upon calling onSubmitProfile()
, it triggers profileFunction()
causing the
<div *ngIf="profileTemplate" class="card card-default color-palette-box">
to become visible. Similarly, if onSubmitContact()
is executed, it should render
<div *ngIf="contactTemplate" class="card card-default color-palette-box">
How can I implement this seamlessly?
Thank you