I am trying to read Json Object from mongodb by doing http call from anhular2 using http provider.
but I am getting the below error in my browser
XMLHttpRequest cannot load http://localhost:3200/pm/workspaces/.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
I tried Below Method i.e. starting chrome by disabling the security restrictions too,but no use:
chrome.exe --disable-web-security
below is my code:
import { Injectable } from 'angular2/core';
import { Http, Response } from 'angular2/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class WorkspaceService {
constructor(private http: Http) { }
getAllWorkspaces(baseUrl:string) {
return this.http.get(baseUrl+'/pm/workspaces/')
.map((res: Response) => res.json()).catch(this.handleError);
}
handleError(error: any) {
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}
Any Suggestions? Thanks in advance.