I trying make a Http request and this issue happens, but I just did the same request before and works, the only diference is the url.
the service file
import { Observable } from 'rxjs/Rx';
import { Http, Response } from '@angular/http';
import { ActivatedRoute, Params } from '@angular/router';
import { Injectable, Inject } from '@angular/core';
@Injectable()
export class SistemaService {
private _apiUrlSistema = 'http://mtz-vweb7/portalEA/api/sistemas';
private route_id: string;
constructor( @Inject(Http) private _http: Http,
@Inject(ActivatedRoute) private route: ActivatedRoute) {
this.route_id = route.snapshot.params.id;
}
getNomeSistema(): Observable<Response> {
return this._http.get(this._apiUrlSistema + '/' + this.route_id)
.map(res => res.json())
.catch(this.throwError);
}
private throwError(Response) {
return Observable.throw(Response.json().error || 'Server error');
}
}
component file
import { ActivatedRoute, Params } from '@angular/router';
import { SistemaService } from './../sistema.service';
import { Component, OnInit, Inject } from '@angular/core';
@Component({
selector: 'app-titulo-sistema',
templateUrl: './titulo-sistema.component.html',
styleUrls: ['./titulo-sistema.component.scss']
})
export class TituloSistemaComponent implements OnInit {
sistema;
constructor( @Inject(SistemaService) private sistemaService: SistemaService,
@Inject(ActivatedRoute) private route: ActivatedRoute) { }
ngOnInit() {
this.sistemaService.getNomeSistema().subscribe((sistema) => {
this.sistema = sistema[0];
},
error => alert(error)
);
}
}
and the HTML5 file
<md-card *ngIf="sistema" >
<md-card-title> {{sistema.Nome}} </md-card-title>
<md-card-content> descrição do sistema </md-card-content>
</md-card>
How I said, I just did it before and works,but now don't and I don't know why. the error is this. they not found the ID.
Failed to load http://mtz-vweb7/portalEA/api/sistemas/undefined: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 404.