An Angular 2 Webpack Starter kit featuring Angular 2, Router, TypeScript, and Webpack by AngularClass
the error you get has something to do with cors. i never used uber api before, try to search on the web http://stackoverflow.com/questions/8685678/cors-how-do-preflight-an-httprequest
for ng2 authentication try https://www.npmjs.com/package/angular2-jwt also if you are not in a hurry read https://medium.com/@blacksonic86/authentication-in-angular-2-958052c64492#.69wcuux91
this is for frontend, you also need to implement the backend counterpart
This error in Mozila :
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.uber.com/v1/products?latitude=12.9716&longtitude=77.5946. (Reason: missing token 'access-control-allow-headers' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel).
This error is in Chrom:
XMLHttpRequest cannot load https://api.uber.com/v1/products?latitude=12.9716&longtitude=77.5946. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.
i am not sure it origin mismatch or token not assigned in the header, i am not using oauth i just want to authenticate with server token provided by the uber api server.
this is my code:
client.service.ts
getEstimatesForUserLocation (lat:number,lon:number) {
let endpoint = 'https://api.uber.com/v1/products';
let url = `${endpoint}?latitude=${lat}&longtitude=${lon}`;
let headers = new Headers();
headers.append('Authorization', 'SERVER_TOKEN');//assigning my server token to header
headers.set('Access-Control-Allow-Origin', '*');
headers.get('Access-Control-Allow-Origin');
headers.append('Access-Control-Allow-Headers','x-requested-with, Content-Type, origin, authorization, accept, client-security-token');
headers.get('Access-Control-Allow-Headers');
return this.http.get(url, {headers})
.map(res => res.json());
}
client.component.ts
getEstimatesForUserLocation() {
this._countryService.getEstimatesForUserLocation(this.lat, this.long )
.subscribe(
data=> this.row = data,
error =>this.error = "location" + this.lat + this.long + "invalid."
);
}
can any one please tell me server token which i am assigning here is correct?
note: i am using @angular/http package
'//@ sourceURL' and '//@ sourceMappingURL' are deprecated, please use '//# sourceURL=' and '//# sourceMappingURL=' instead.
and a lot of them warnings whenever the application bootstraps90% optimize assetsError in bail mode: [default] /Users/Daily/Shortcut-Webpack/typings/browser/ambient/jquery/index.d.ts:3223:12
Subsequent variable declarations must have the same type. Variable '$' must be of type 'cssSelectorHelper', but here has type 'JQueryStatic'.
and I cannot figure out how I fixed it the first time, does anyone know?
@meiblorn
Hi, guys! I need help.
I am trying to write quick start for system.js for my first open source library: http://plnkr.co/edit/oeOnHTmWasmOgRhbKkcB?p=preview.
It throws "$ is not a function" error.
I am using typings in my project but don't know how to install typings in plnkr.
Help me to fix it, please.
(<any>$)(this._el.nativeElement).fullpage(this.options);