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