I have Ionic 4 angular project, I need to assign value while reading inside subscribe. However I could not do that. I know there are several Questions and Answers related to mine. However none of them is working for me. Here is the my code and I tried so far. Any comments, any help is appriciated. Thank you very much.`
Service.ts
public loggedChecker: any;
private lofff = new Subject<any>();
postLoginToServer (password, email) {
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
let postData = {
password: password,
mail: email
}
console.log("8888888888888888888888888888888");
this.http.post("http://localhost:8080/api/login", postData, { observe: 'response'} )
.pipe(map(data => this.loggedChecker =(data.body)));
console.log(this.loggedChecker,"0330303333333333"); //undefined
return this.loggedChecker+"";
}
And here is the another I try
postLoginToServer (password, email) {
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
let postData = {
password: password,
mail: email
}
this.http.post("http://localhost:8080/api/login", postData,{observe: 'response'})
.subscribe(data => {
this.loggedChecker =(data.body);
this.textToDisplay = (data.body);
this.lofff.next(data);
}, error => {
console.log(error);
});
console.log(this.lofff,"logged checker");
return this.loggedChecker+"";
}
Here is the page.ts
Page.ts
logForm(){
console.log(this.fineService.postLoginToServer(this.passwordUser, this.email));
}
Both of them are not working. Thank you.
this.loggedChecker = data.body;this.http.post("http://localhost:8080/api/post", postData,{observe: 'response'})and then subscribe to it wherever you want.