【发布时间】:2017-05-13 20:48:48
【问题描述】:
我是 Angular 2 的新手,仍在学习我正在尝试使用 get 调用来访问 URL,但即使在浏览器的网络中,get 似乎也没有通过,我找不到调用的 get URL。
程序将转到该方法控制台记录该 get 调用的上方和下方,但 get 调用没有任何内容
我的服务方式
import { Headers, Http, Response } from '@angular/http';
import { Injectable } from '@angular/core';
import { Persons } from './mock-people';
import { Person } from './person';
import {Observable} from 'rxjs/Rx';
getAllPersons(): void {
console.log("Here");
this.http.get(`http://swapi.co/api/people/1`)
.map((response: Response) => {
console.log(response.json());
response.json();
});
console.log("Comes here 2");
}
在 app.module.ts 中导入 HttpModule
我的控制台屏幕截图
【问题讨论】:
-
我在调试时错过的重要事情:
you should subscribe to it to make it work.
标签: angular angular-http