Recently, I have been exploring Angular and encountered a situation where I need to retrieve a value from a method using subscription. The method in question is designed to return an object with properties {ClientId, ClientSecret}, but I must admit that I am still unclear on how exactly this method operates.
clientSecret(merchantId: number): Observable<void> {
let url_ = this.baseUrl + "/api/PosQR/{merchantId}/client-secret";
if (merchantId === undefined || merchantId === null)
throw new Error("The parameter 'merchantId' must be defined.");
url_ = url_.replace("{merchantId}", encodeURIComponent("" + merchantId));
url_ = url_.replace(/[?&]$/, "");
let options_ : any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
})
};
return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any)
=> {
return this.processClientSecret(response_);
})).pipe(_observableCatch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processClientSecret(response_ as any);
} catch (e) {
return _observableThrow(e) as any as Observable<void>;
}
} else
return _observableThrow(response_) as any as Observable<void>;
}));
}
In an attempt to subscribe to the method within ngOnInit and store the retrieved value in a local variable, I wrote:
this.posQrClient.clientSecret(2343).subscribe(res => {
this.clientId = res[ClientId]
});
However, the output is returning null. Despite my attempts at troubleshooting, I have not been successful in resolving this issue. Any assistance or guidance would be greatly appreciated.