I have a service where I set the ID, I get this ID from another component on a click event.
export class MyService {
id: number;
constructor() {}
public setId(value: number) {
this.id = value;
console.log('id:', this.id);
}
}
The value gets set on this click event I have inside my menu component:
<a [routerLink]="['item.id]" (click)="getId(item.id);">
which triggers this method inside the menu component:
getId(datavalue: number)
{
this.ms.setId(datavalue);
}
How could I send that same value to another component so I can use it for display in HTML?
class MyComponent implements OnInit
{
id: number;
constructor(private ms: MyService)
{
this.id = ms.id;
console.log('ms id = ', this.id);
}
I've tried it like in the example above but I'm getting "undefined" in the console log.