我正在尝试使用带有Typescript的angular 2进行简单的HTTP GET请求.我收到404错误,空url.下面显示的是我的组件文件,以及我收到的错误.
import { Component,OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { BreadcrumbService } from './breadcrumbService'; import { Http,Response } from '@angular/http'; @Component({ moduleId: module.id,providers: [ BreadcrumbService],templateUrl: 'html/appList.html',styleUrls: ['css/list.css'] }) export class HealthComponent { constructor(private http: Http) { this.http.get('http://jsonplaceholder.typicode.com/posts/1') .toPromise() .then((res: Response) => { console.log('RES: ',res); }) .catch((err: Error) => { console.log('ERR!!: ',err); }); } }
错误消息:
Response {_body: Object,status: 404,ok: false,statusText: "Not Found",headers: Headers…} _body:Object headers:Headers ok:false status:404 statusText:"Not Found" type:2 url:null __proto__:Body