[英]Angular - post a comment to database
I am trying post a comment from an input form to my database. 我正在尝试将输入表单中的评论发布到我的数据库中。 The comment I am passing in currently logs as undefined.
我正在传递的评论当前未定义记录。 The service doesn't log and I get a 500 server error: user_id violates not null constraint.
服务未记录,并且出现500服务器错误:user_id违反了非null约束。 What am I doing incorrectly?
我做错了什么?
HTML(updated) HTML(更新)
<div ng-controller="CommentsCtrl as commentsCtrl">
<div ng-show="makeComment" class="collapsible-header">
<input ng-model="comment" type="text" name="comment" id="comment_content" class="col s11 m11 l11" placeholder="Make a comment.">
<a href="" type="submit" class="col s1 m1 l1 black-text comment" ng-click="commentsCtrl.createComment(comment, userId, postId)"><i class="material-icons">check_circle</i></a>
</div>
Controller - CommentsCtrl(Updated) 控制器-CommentsCtrl(更新)
this.comment = '';
createComment(comment, userId, postId) {
return this.commentsService.createComment(comment, userId, postId);
}
}
Service - CommentsService(Updated) 服务-CommentsService(已更新)
this.createcomment = $http;
this.commentContent = '';
this.postId;
this.userId;
createComment(comment, userId, postId) {
this.createcomment.post('/comments', { comment: this.commentContent, userId: this.userId, postId: this.postId })
.then((res) => {
this.comment = res.data;
})
.catch((err) => {
return err;
});
}
You are not passing any values for userId or postId: 您没有传递userId或postId的任何值:
this.commentsService.createComment(comment);
They are null. 它们为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.