appComponent 및 this.loggedIn = this.authenticationService.isLogged;
이 있습니다.각도 2의 var 참조
그래서 appComponent는 authenticationService를 사용하고 그로부터 isLogged 데이터를 가져옵니다. this.loggedIn
에 서비스 데이터에 대한 참조가 있다고 가정합니다.
는 지금은 appComponent에서 방법을 실행하면
logout() {
this.authenticationService.isLogged = false;
}
this.loggedIn
false로 변경해야합니다. 그러나 그렇지 않습니다. appComponent.ts의 다음
부분 :
import {AuthenticationService} from './auth_service/auth_service';
@Component({
selector: 'my-app',
styleUrls: ['app/app_component.css'],
templateUrl: './app/main_app_template.html',
directives: [ ROUTER_DIRECTIVES],
providers: [ SendLoginService, AuthenticationService, ConfigurationService, SetupIntervalService]
})
export class AppComponent {
loggedIn ;
constructor (private authenticationService: AuthenticationService
}
ngOnInit() {
this.loggedIn = this.authenticationService.isLogged;
}
logout() {
this.authenticationService.isLogged = false;
console.log(this.loggedIn); //returns: true . but should return 'false'
}
authenticationService.ts :
import {Injectable} from '@angular/core';
@Injectable()
export class AuthenticationService extends HttpBaseClass {
isLogged = true;
}
, 당신은 그것을 확인한다? –