I am trying to grasp the situation happening here. I have two variables activeToInactive
and inactiveToActive
which I increase whenever a status is updated. Here's my code snippet:
Counter Service:
export class CounterService {
// Initial States
activeToInactive = 0
inactiveToActive = 0
incrementStatusCount(statusCount: number) {
// Incrementing either of the initial states each time the function is called.
statusCount++
if (statusCount == this.activeToInactive) {
console.log(`${statusCount} - changing from active to inactive`)
}
if (statusCount == this.inactiveToActive) {
console.log(`${statusCount} - changing from inactive to active`)
}
// I'm observing that statusCount doesn't match the initial states, causing the if statements to evaluate as false
}
}
Transfer Service:
import { Injectable } from "@angular/core";
import { CounterService } from "./counter.service";
@Injectable()
export class transferService {
constructor(private Counter: CounterService) {}
activeUsers = ['Max', 'Anna'];
inactiveUsers = ['Chris', 'Manu']
setToInactive(id: number) {
this.inactiveUsers.push(this.activeUsers[id]);
this.activeUsers.splice(id, 1);
// Invoking the function from a different service
this.Counter.incrementStatusCount(this.Counter.activeToInactive)
}
setToActive(id: number) {
this.activeUsers.push(this.inactiveUsers[id]);
this.inactiveUsers.splice(id, 1);
// Invoking the function from a different service
this.Counter.incrementStatusCount(this.Counter.inactiveToActive)
}
}
Whenever either function in Transfer Service is triggered, the initial states are not being incremented. It seems that statusCount
does NOT match any of the initial states. Could this be related to references? I haven't fully grasped them yet, so if you have any suggestions on how to approach this issue, please share.
Appreciate your help in advance!!!