Node.js 角度传感器响应不正确
我是nodejs&angular的新手 这是我的restAPI函数:Node.js 角度传感器响应不正确,node.js,angular,Node.js,Angular,我是nodejs&angular的新手 这是我的restAPI函数: exports.getPlanningStages = async (req, res, next) => { const currentPage = req.query.page || 1; const perPage = 2; try { const totalItems = await Planningstage.find().countDocuments(); const plan
exports.getPlanningStages = async (req, res, next) => {
const currentPage = req.query.page || 1;
const perPage = 2;
try {
const totalItems = await Planningstage.find().countDocuments();
const planningstages = await Planningstage.find()
.populate('creator')
.sort({ createdAt: -1 })
.skip((currentPage - 1) * perPage)
.limit(perPage);
res.status(200).json({
planningstages
});
} catch (err) {
if (!err.statusCode) {
err.statusCode = 500;
}
next(err);
}
};
在控制台上,我看到了正确的json数组响应
角度代码是
计划阶段.服务.ts
private ps: Planningstage[] = [];
getPlanningStages() {
return this.httpService
.get<Planningstage[]>(
"http://localhost:8080/planningstage/getPlanningStage"
);
}
ngOnInit() {
this.fetch();
}
fetch() {
this.psService.getPlanningStages().subscribe(resData => {
console.log(resData);
});
浏览器上的响应
如何读取角度代码处的电流响应
谢谢看来您的问题出在这条线路上
res.status(200).json({
planningstages
});
不要在上面画线,像这样画
res.status(200).json(planningstages);