0
Ich versuche, die WEB-API von http.get
zugreifen, aber es funktioniert nicht das ist der Dienst, in dem ich Observable benutze, aber es funktioniert überhaupt weder Aufruf zum Server und nicht angezeigt irgendein Fehler auch.Observables funktioniert nicht angular 2 auf webapi
@Injectable()
export class SetupServiceObservables {
public apiServiceBaseUri = 'http://localhost:3000/';
private authheaders: any = {};
private config: any = {};
private auth: any = {};
constructor(private http: Http, private ngWEBAPISettings: WebAPISettings, private authService: AuthService, private router: Router) {
}
public get(servicename: string): Observable<any> {
return this.http.get(this.ngWEBAPISettings.apiServiceBaseUri + "api/" + servicename + "/", this.getConfig())
.map(this.extractData)
.catch(this.handleError);;
}
public getConfig() {
this.authheaders.Authorization = this.auth.access_token == "" ? "" : 'Bearer ' + this.auth.access_token;
this.config = {
headers: {
'Authorization': this.authheaders.Authorization
},
cache: false,
};
return this.config;
}
private extractData(res: Response) {
let body = res.json();
console.log(res);
return body.data || {};
}
private handleError(error: any) {
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}
danke für die Hilfe, die ich nicht abonniert habe – rashfmnb