Host listener doesn't work. The function which triggers the request is being called but, the post-operation does not invoked. Can anyone help with this?
app.component.ts
@HostListener('window:beforeunload', ['$event'])
onWindowClose($event) {
console.log('market unlocked');
this.unlockAlias();
return true;
}
constructor(private router: Router, private service: Adal5Service, private http : Http) {
this.service.init(config);
}
ngOnInit() {
this.service.handleWindowCallback();
this.isAuthenticated = this.service.userInfo.authenticated;
}
unlockAlias() {
const apiEndPoint = environment.baseUrl + environment.unLockAlais;
const body = '{"uid": "' + this.service.userInfo.username + '" }';
const headers = new Headers({ 'Content-Type': 'application/json' });
headers.append('Access-Control-Allow-Origin', '*');
const options = new RequestOptions({ headers: headers });
this.http
.post(apiEndPoint,
body, options)
.subscribe(data => {
console.log("unlocked");
}, error => {
console.log(JSON.stringify(error.json()));
});
}}