我遇到了一个问题:我想在博客平台上做一些评论,并在数据库中添加评论。你能解释一下为什么$scope.comment
是undefined
吗?我认为一切都很好,但事实并非如此。
控制器
app.AddComment = function(comment, valid) {
var userComment = {};
userComment._id = app.currentProduct;
userComment.comments = $scope.comment
console.log($scope.comment)
app.disabled = true;
//app.loading = true;
app.errorMsg = false;
if(valid){
User.postComment(userComment).then(function(data){
console.log(userComment);
if(data.data.success){
console.log('ok')
} else {
app.disabled = false;
//app.loading = false;
app.errorMsg = data.data.message;
console.log(data.data.message);
}
});
} else {
app.disabled = false;
}
}
form.html
<form name="AddCommentForm" ng-submit="seeMore.AddComment(comment, AddCommentForm.$valid)">
<textarea class="form-control" id="text-area-comment" name="comment" ng-model="comment"></textarea>
<button class="btn btn-warning button-comment-user">Add</button>
</form>
服务
userFactory.postComment = function(comment){
return $http.post('/api/comments', comment);
}