I'm trying to create a variable in my service, that would be accessable whenever I inject this service. However, I cannot populate my login$
of BehaviorSubject type. I checked this and this, but I'm having difficulties understanding how it's working.
Component
this.loginService.login = user.value.username; // OK
this.loginService.pass = user.value.password; // OK
this.loginService.emitLogin(user.value.username); // UNDEFINED - user.value.username is input field of form group
LoginService
export class LoginService {
public login: string;
public pass: string;
public login$ = new BehaviorSubject(this.login);
emitLogin(value: string) {
this.login$.next(value);
}
constructor(private http: Http) { }
}
Also, I'd like to use login$
in my DriverService
. Here's what have I done till now:
DriverService
export class DriverService {
private login;
constructor(private http: Http, private loginService: LoginService) {
this.loginService.login$.subscribe(value => {
console.log(value);
this.login = value;
});
}
}
How can I populate and properly, and make it usable in other services?
Thanks