간단한 방법이 있지만 찾을 수없는 것 같습니다. 여기Angular2 : 익명 함수 내에서 클래스 변수에 액세스
export class UserLoginComponent {
private user: User;
public authService: AuthService;
constructor(private cognitoConfigs: CognitoUtil, authService: AuthService) {
this.user = new User();
this.authService = authService;
}
authenticate() {
// Some work being done here
let cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function(result: any) {
this.authService.login(this.user, result);
},
onFailure: function(err: any) {
console.log(err.message);
},
});
}
}
문제 내 코드는 다음으로 onSuccess 콜백에서 나는 그것이 부모 클래스의 속한 this.authService
변수에 액세스 할 수 없습니다.