如何制作邮寄请求 angular 在节点的服务器上
当我在节点服务器上打印查询的内容时,我不会在任何地方看到用户数据。
这是我的节点服务器:
但是代码 Angular2:
任何人都可以帮助我或解释如何处理请求 http 在 angular.
这是我的节点服务器:
var http = require/'http'/;
http.createServer/ function /request, response/ {
console.log/request/;
}/.listen/8080/;
console.log/'Server running at [url=http://127.0.0.1:8080]http://127.0.0.1:8080[/url]/'/;
但是代码 Angular2:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { Http, Response, Headers , RequestOptions } from "@angular/http";
import 'rxjs/add/operator/retry'; // to be able to retry when error occurs
import { Observable } from "rxjs/Rx";
@Component/{
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
}/
export class AppComponent implements OnInit{
title = 'Angular Test';
user = { id : 1, name : "Hello"};
constructor /private http: Http/ {}
ngOnInit//: void {
let headers = new Headers/{ 'Content-Type': 'application/json' }/;
let options = new RequestOptions/{ headers: headers }/;
console.log/this.user/;
this.http.post/"[url=http://localhost:8080/"]http://localhost:8080/"[/url], this.user, options/
.subscribe/
/err/ => {
if/err/ console.log/err/;
console.log/"Success"/;
}/;
}
}
任何人都可以帮助我或解释如何处理请求 http 在 angular.
没有找到相关结果
已邀请:
2 个回复
冰洋
赞同来自:
这是您的客户 angular:
逆流
https://github.com/kuncevic/an ... mples
君笑尘
赞同来自:
你的节点部分 app.js, 它应该是这样的 /假设你用了什么 expressjs 和...一起 node.js/:
app.js
:
使用此配置节点,当您发送内容时
, 你会得到
作为逆向订阅呼叫中的答案。