Tag: angular度http

Angular 2 http没有得到

我新来Angular 2仍然学习我正在尝试打一个电话的url,但即使在浏览器的networking中似乎没有通过我无法find被调用的URL。 该程序是去那个方法控制台日志logging上面和下面,得到调用,但没有任何获取调用 我的服务方法 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 我的控制台屏幕截图 安慰

AngularJs $ http.post()不发送数据

任何人都可以告诉我为什么以下声明不发送发布数据到指定的url? URL被调用,但在服务器上,当我打印$ _POST – 我得到一个空的数组。 如果我在控制台中打印消息,然后将其添加到数据 – 它显示正确的内容。 $http.post('request-url', { 'message' : message }); 我也试着用数据作为string(具有相同的结果): $http.post('request-url', "message=" + message); 当我以下列格式使用它时,它似乎正在工作: $http({ method: 'POST', url: 'request-url', data: "message=" + message, headers: {'Content-Type': 'application/x-www-form-urlencoded'} }); 但有没有办法做到这一点$ http.post() – 我总是必须包括头为了它的工作? 我相信上面的内容types是指定发送数据的格式,但是我可以把它作为javascript对象发送吗?