app.get("/api/products",(req,res)=>{
res.json(products)
})
app.get("/api/products/:id",(req,res)=>{
//在命令行中打印...const server =app.listen(8000,"localhost",()=>{
console.log("服务器已经启动,地址是http://localhost:8000")
});
接着在本地从创建好的服务器上获取数据.../product.component.html',
styleUrls: ['....中引入过了,这里需要声明在构造函数里头,并引入Http from "@angular/Http";
接着就是坑了,写完后,发现还是获取不到服务器上的数据:
接下来还有配置:
在根目录新建一个文件:proxy.conf.json... 内容为:
{
"/api":{
"target":"http://localhost:8000"
}
}
然后在package.json文件中,修改一行
"start": "ng serve