我想让我的角度应用程序,我的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