【发布时间】:2020-07-31 15:44:48
【问题描述】:
我正在尝试实现我为其创建节点服务器的 MEAN 应用程序
app.get("/posts",(req,res)=>{
posts=[{"title":"a","context":"b"},{"title":"c","context":"d"}]
res.send(posts); // tried even with res.status(200).json(posts)
});
当它使用 api tester 检查时,它运行良好,输出快照 output snapshot with apitester
当我尝试使用角度服务访问时
getposts()
{
var url='http://localhost:3000/posts';
this.http.get<post[]>(url).subscribe(data=>this.posts=data);
console.log(this.posts);
return this.posts;
}
当我执行 console.log(posts) 时,它返回 []
有人可以帮我在过去 2 天里苦苦挣扎吗?
【问题讨论】:
-
不可以请你写下这个问题的答案
标签: node.js angularjs api mean-stack