I recently developed an Angular service with a basic string variable that gets updated within the service. The issue arises when trying to access the updated value in my component.ts file after calling the function responsible for updating it.
Below is the code snippet for the service:
import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';
import { HttpService } from '../http/http.service';
@Injectable({
providedIn: 'root',
})
export class MyService {
constructor() {}
callLogsToggle = 'on';
The following function is created within this service:
public setHubspotTogglesStatus() {
this.callLogsToggle = 'off'; //value is updated to off
}
This is how the component.ts file looks like:
import { ActivatedRoute, Router } from '@angular/router';
@Component({
selector: 'my-selector',
templateUrl: './myCompo.component.html',
styleUrls: ['./myCompo.component.sass'],
})
export class MyComponent implements OnInit {
constructor(
private mySevice: MyService,
) {
this.myService.setHubspotTogglesStatus()
console.log(this.mySevice.callLogsToggle) //Output remains as "on"
//despite attempting to update
}
If you have any suggestions on how to resolve this particular issue, please let me know. Your help is greatly appreciated.