I have a service in my component, this service has a method that returns a string value from the server.
Service:
getOrderBarcode(): Observable<string> {
return this.http.get(this.baseUrl + 'barcode/getbarcode')
// .map(this.extractData);
.map(res => res as string )
}
Component:
let barcodeService = this.barcodeService.getOrderBarcode();
debugger;
barcodeService.subscribe(result => order.OrderBarcode = result);
console.log(order.OrderBarcode);
// rest of the logic
However, when the .subscribe
is called it is not binding the value at this point, after debugging I found that it applies the value after executing everything in the class, how can I get around this issue?
UPDATE based on the comments and link to another question
Service method:
getSomething(callback: (data) => void) {
debugger;
return this.http.get(this.baseUrl + 'barcode/getbarcode')
// .timeout(1000)
// .map(this.extractData);
.map(res => res as string)
}
Component:
let a = this.barcodeService.getSomething((data) => {
debugger;
console.log(data);
});
This debugger does not get hit...