Angular 8 Injectable Globals does not maintain value

34 Views Asked by At

I have declared a global.ts file:

@Injectable()
export class Globals {
  utentePuntoVendita: boolean = false;
[...]
}

In the constructor of my components I read this variable and do something. The first component that is loaded correctly reads it. Then if I navigate to another component (from the first one, so a second page level) I can see that the value in globals is inverted.

How is that possible?

I've checked and I've never reassign the value in globals, I only read it.

This is how I read it:

constructor(
    private global: Globals
  ) {
    this.utentePuntoVendita= this.global.utentePuntoVendita;
}

I've tried to print global in console and I've noticed something very strange:

[enter image description here]

and this is for every console.log of global, in every component. But only the first one is somehow capable of reading the correct value. What's happening?

0

There are 0 best solutions below