// I was trying to get the values from outside the subscribe but it cannot assign to any variable. In my project, get the json content using http.post() method and assigned it to a variable. I want to access these variable value outside the constructor ..How can I make it possible ?
ngOnInit(): void {
this.getSubscription();
}
// here is my subscription function
getSubscription() {
interval(5000)
.pipe(
startWith(0),
switchMap(() => this._subscriptionService.getSubData()))
.subscribe(data => {
this.Result = data; // able to print the data
JSON.stringify(this.Result);
console.log(this.Result); // able to print the data
});
console.log(this.Result); // undefined is printing
}
// I want to access this.result outside the subscribe and assigned to a public variable