我想讓我的角度應用程序,我的REST API之間的連接。 這返回JSON http://is.njn.mvm.bg/check。所以我的問題是我需要哪些提供者,因爲我包含在app.module中,但它仍然不起作用。 import { HttpModule} from '@angular/http';
我使用Angular2 HTTP教程Angular2 HTTP請求供應商
private heroesUrl = 'http://is.njn.mvm.bg/check'; // URL to web API
constructor (private http: Http) {}
getHeroes(): Observable<Hero[]> {
return this.http.get(this.heroesUrl)
.map(this.extractData)
.catch(this.handleError);
}
我越來越XMLHttpRequest cannot load http://localhost:8000/da. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
您正在引發CORS爲其中一個答案顯示。您可以將靜態的angular2內容移動到服務於REST調用的服務器上,大多數現代Java服務器也可以提供靜態內容。問題是localhost:3000服務於內容,localhost:8000服務於REST調用,這是不允許的。 – AlexC