Angularjs 角度和猫鼬-无法访问某些用户值。其他的看起来不错
我正在创建一个评论系统,并试图向视图中添加一些值,如文本、用户名、timePosted和userProfileImageURL,但唯一不会出现的是userProfileImageURL 我认为问题出在控制器功能上,但它可能完全在其他地方Angularjs 角度和猫鼬-无法访问某些用户值。其他的看起来不错,angularjs,node.js,mongodb,Angularjs,Node.js,Mongodb,我正在创建一个评论系统,并试图向视图中添加一些值,如文本、用户名、timePosted和userProfileImageURL,但唯一不会出现的是userProfileImageURL 我认为问题出在控制器功能上,但它可能完全在其他地方 /** * Comment middleware */ exports.commentByID = function (req, res, next, id) { Comment.findById(id).populate('user', 'dis
/**
* Comment middleware
*/
exports.commentByID = function (req, res, next, id) {
Comment.findById(id).populate('user', 'displayName').exec(function (err, comment) {
if (err) return next(err);
if (!comment) return next(new Error('Failed to load Comment ' + id));
req.comment = comment;
next();
});
};
或者在这里
/**
* List of Comments
*/
exports.list = function (req, res) {
var id = req.dealId;
console.log('Log - ' + id);
Comment.find( )
.sort('-created')
.populate('user', 'displayName')
.exec(function (err, comments) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(comments);
}
});
};
此函数中的“user”和“displayName”参数的作用是什么
我能否以某种方式将“userProfileImageURL”也添加到返回的数据中
我像这样使用profileImageURL值。显示名称正在显示,但未显示profileImageURL
<img ng-src="{{post.user.profileImageURL}}" alt="{{post.user.displayName}}" />
只需删除displayName参数,它就会发送整个用户对象
/**
* List of Comments
*/
exports.list = function (req, res) {
var id = req.dealId;
console.log('Log - ' + id);
Comment.find( )
.sort('-created')
.populate('user')
.exec(function (err, comments) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(comments);
}
});
};