我开始使用Angular 2,在第一次尝试从JSON文件获取数据并将其显示在表上并完成后,现在我想从rest api获取数据,所以我从Entity类创建Restful webservices ,我生成了CrossOriginResourceSharingFilter(我使用netbeans和glassfish),我得到了JSON输出的链接,我在角度2中替换api url中的链接但是它不起作用 这在我的Angular 2雇员。服务
@Injectable()
export class EmployesService {
private empsUrl = 'localhost:25176/WebApplication4/app/employes'; // URL to web api
constructor(private http: Http) { }
getEmployes (){
return this.http.get(this.empUrl)
.map(res=> res.json())
.catch(this.handleError);
}
这是我的雇员。组件
export class EmployesComponent implements OnInit{
emps: Employe[];
error: any;
mode = 'Observable';
errorMessage :string;
constructor(private empService: EmployesService,private _elRef :ElementRef) { }
getEmployes() {
this.empService.getEmployes()
.subscribe(
employes => this.emps = employes,
error => this.errorMessage = <any>error);
}
ngOnInit() {
this.getEmployes();
这是我的控制台错误
zone.js:101 XMLHttpRequest cannot load localhost:25176/WebApplication4/app/employes. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
谢谢你的帮助