I'm trying to pass data between two different components with no relationship but am having some difficulties. Does anyone have any recommendation on how to do this? Example:
I've got a page with 3 buttons. passing a string value upon click to a variable called selectAgent.
~agents.html~
<div routerLink="/lineups/brimstone" (click)="selectAgent('brimstone')"> </div>
<div routerLink="/lineups/viper" (click)="selectAgent('viper')"> </div>
<div class="col sova" routerLink="/lineups/sova" (click)="selectAgent('sova')"> </div>
Now, i'm trying to pass selectAgent into another component (called maps):
~maps.html~
<h5> selected agent: {{selectedAgent}} </h5>
<div class="select row mx-auto">
<div class="col" *ngFor="let map of maps">
<img src={{map.url}} (click)='openMap(map.name)'/>
</div>
</div>
Which will also be appended into the URL on click:
~maps.component.ts~
openMap(setMap: any) {
this.router.navigateByUrl(`/lineups/${selectedAgent}/${setMap}`);
console.log(setMap);
}
My goal is to pass the clicked variable into the h5 tag. Does anyone have any suggestions I can go off?