("/api/products",(req,res)=>{
res.json(products)
})
app.get("/api/products/:id",(req,res)=>{
//在命令行中打印...,地址是http://localhost:8000")
});
接着在本地从创建好的服务器上获取数据:
import { Component, OnInit } from '@angular/core'....对应 的需要引入Observable from "rxjs"
http服务已经在app.module中引入过了,这里需要声明在构造函数里头,并引入Http from "@angular/Http";...接着就是坑了,写完后,发现还是获取不到服务器上的数据:
接下来还有配置:
在根目录新建一个文件:proxy.conf.json 内容为:
{
"/api":{
"target":"http...然后启动
要用npm run start;
只要使用这个命令,才能告诉页面,需要到这个地址去拿数据.