내 app.component각도이 문제
import { Component, OnInit } from '@angular/core';
import { AngularFire } from 'angularfire2';
import { Subscription } from 'rxjs/Subscription';
import { MainService } from './main.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
private logsub: Subscription;
private checking: string;
constructor(private af: AngularFire, private mainService: MainService){}
ngOnInit(){
this.logsub = this.mainService.userThere$.subscribe(isUser => {
if (isUser){
firebase.auth().onAuthStateChanged(function(user){
if (user){
this.mainService.userLogged(true);
alert("True");
}
else {
this.mainService.userLogged(false);
}
});
}
});
if (this.mainService.userLogged){alert("Fish");}
}
ngOnDestroy(){
this.logsub.unsubscribe();
}
}
내 main.services
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class MainService {
private userThere = new Subject<boolean>();
userThere$ = this.userThere.asObservable();
userLogged(isUser: boolean){
this.userThere.next(isUser);
}
}
이 내가 여기에 이해하지 오전. 사용자 인증 코드가 있습니다. 사용자가있는 경우 alert("True")
이 표시됩니다. 또한 userLogged
구독을 설정했습니다.
내 페이지를로드 할 때 사용자가 없음을 확인할 수 있습니다. 나는 alert("True");
을 얻지 못한다. 그러나이 아래에는 테스트 코드 if (this.mainService.userLogged){alert("Fish");}
이 포함되어 있습니다.
사용자가 없는데도 불구하고 나는 여전히 물고기에 대해 경고를 받고 있습니다. 즉 (}는 mainService
로서
가 컴포넌트에 주사된다
데 도움이 기능으로'userLogged'는 –
그래서 어떻게 내 if 문을 포맷 할 수 정의? – abrahamlinkedin