I have defined this service in my Angular Application.
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class LoginstatusService {
logBtn: string = '';
logStat: string = '';
login: any;
constructor() {}
setBtn(data: any) {
this.logBtn = data;
console.log(data);
}
getBtn(): string {
return this.logBtn;
}
setStatus(data: any) {
this.logStat = data;
console.log(data);
}
getStatus(): string {
return this.logStat;
}
I could set the value to this service from a component and could log the value in the console and check. However, when I try to use the value in the onInit() method of another component, it just returns undefined, instead of the expected value. Could someone explain this behavior, and help me fix this? Thanks in advance.