I am looking to save and display comment data in the view and store it in a database.
Below is the form I have:
<form>
<div class="form-group">
<label>Add a comment</label>
<input type="text" ng-model="newRole.newAuthor" placeholder="author">
<input type="date" ng-model="newRole.newDate">
<input type="file" ng-model="newRole.commentImage">
<textarea class="form-control metro" ng-model="newRole.newComment"></textarea>
<h2>{{txtcomment}}</h2>
</div>
</form>
<button class="btn btn-primary" ng-click="trip.makeComment(newRole)">Comment</button>
I want to store the data at this location:
this.tripObject.comments = [
{
"author": "Ronnie Oliver",
"date": "05/06/16 01:19 PM",
"imageURL": "/assets/images/placeholders/user.svg",
"text": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor."
},
{
"author": "Shaggy Rogers",
"date": "05/06/16 12:48 PM",
"imageURL": "/assets/images/placeholders/user.svg",
"text": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor."
}
];
This is how the controller looks like:
this.makeComment = function(newRole){
// $scope.txtcomment = '';
var newRole = {
"author":newRole.newAuthor,
"date":$scope.newDate,
"imageURL":$scope.commentImage,
"text" : $scope.newComment
}
console.log($scope.newRole);
console.log($scope.tripObject.comentario)
this.tripObject.comments.push($scope.newRole);
console.log(this.tripObject.comments);
};
I suspect there might be an issue with either the controller or the form, but I'm not sure exactly where.