首先创建服务器:
1.最好使用express,这个库有更多的api,方法:npm install express --save;
2. npm install @types/express --save...;
安装nodemon 可以让服务器自动重启,
方法:npm install nodemon;
在启动服务器的时候用:nodemon build/...js;
这样服务器就算启动完成了.
/**
*...app.get("/api/products",(req,res)=>{
res.json(products)
})
app.get("/api/products/:id",(req,res)=>{
//在命令行中打印...app.module中引入过了,这里需要声明在构造函数里头,并引入Http from "@angular/Http";
接着就是坑了,写完后,发现还是获取不到服务器上的数据:
接下来还有配置:
在根目录新建一个文件...:proxy.conf.json 内容为:
{
"/api":{
"target":"http://localhost:8000"
}
}
然后在package.json文件中,修改一行