Currently, I am attempting to transform a google maps direction service into an Observable pattern. Here is an example taken from https://developers.google.com/maps/documentation/javascript/examples/directions-simple:
function calculateAndDisplayRoute(directionsService, directionsDisplay) {
directionsService.route({
origin: document.getElementById('start').value,
destination: document.getElementById('end').value,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
I have attempted the following:
import { Observable } from 'rxjs/Observable';
...
// the callback version works
getRoute (route: any) {
const defaults = { 'travelMode': 'WALKING' };
route = Object.assign(defaults, route);
this._directionsService.route(
route
, (res:any, status:string) => {
if (status == 'OK')
this.displayRoute(res);
else
this.handleError(res)
})
}
// the Observable version doesn't progress past typescript
getRoute$ (route: any) {
const defaults = { 'travelMode': 'WALKING' };
route = Object.assign(defaults, route);
let route$ = Observable.bindCallback(
this._directionsService.route
, (res, status)=>{res, status}
);
// TypeScript indicates, "Supplied parameters do not match any signature of call target
route$( route ).subscribe(
(resp:any)=>{
// also, how do I throw an error from the selector func?
if (resp.status == 'OK')
this.displayRoute(resp.res);
else
this.handleError(resp.res)
}
)
}
Why is TypeScript rejecting this particular pattern?