angularjs - Trouble getting Comment Form to POST - Angular App -


i'm relatively new angular. i'm trying comment form of blog app post comments , not keep them in javascript via api post database , store them there. i'm able comments other blog post information whatever reason can't post.

blogservice.js

angular.module('blogservice', [])   .factory('blogservice', ['$http', function($http) {      return {         // call blog api         : function() {             return $http.get('/api/blog');         },         // call blog api via id         show : function() {             return $http.get('/api/blog/' + id);         },         // call post new data using blog api         create : function(blogdata) {             return $http.post('/api/blog', $scope.formdata);         },         // call post comments in blog api         createcomment : function(commentdata) {           return $http ({             method: 'post',             url: '/api/blog/' + id + '/comments',            header: { 'content-type' : 'application/x-www-form-urlencode},             data: $.param(commentdata)           });         },          // call put update data using blog api         update : function(id) {            return $http.put('/api/blog' + id);         },          // call delete data using blog api         delete : function(id) {             return $http.delete('/api/blog/' + id);         }     }  }]); 

commentctrl

to note, commentctrl part of larger blogctrl.js. separated own controller. if it'll help, can post whole file.

...

.controller('commentctrl', ['$scope', '$http', 'blogservice', function($scope, $http, blogservice) {   this.commentdata = {};    this.addcomment = function(post) {     blogservice.createcomment(this.commentdata)       .success(function(data) {         this.commentdata = {};         this.commentdata.createdon = date.now();         post.comments.push(this.commentdata);         this.commentdata = {};     })     .error(function(data) {       console.log('error: ' + data);     });   };  }]); 

blog.html form part i'm trying post. snippet of markdown. let me know if see whole html file.

  <div class="post" ng-repeat="post in blog.posts" ng-show="blog.isselected($index)">     <div>       <h2>{{post.title}}</h2>       <img ng-src="{{post.image}}" ng-show="{{post.image}}"/>       <cite>by {{post.author}} on {{ post.createdon | date:'medium' }}</cite>       <div class="post-body">         <p>{{post.body}}</p>       </div>       <div ng-controller="commentctrl cmtctrl">         <button class="icon-button" ng-click="post.likes = post.likes+1">           <i class="fa fa-thumbs-up"></i> {{post.likes}}         </button>         <button class="icon-button" ng-click="post.dislikes = post.dislikes+1">           <i class="fa fa-thumbs-down"></i> {{post.dislikes}}         </button>         <h3> comments <h3>         <form class="form-style" name="commentform" ng-submit="commentform.$valid && cmtctrl.addcomment(post)" novalidate>           <h4> add comment: </h4>           <div>             <input type="text" class="comment-form form-control input-lg" name="body" ng-model="commentdata.body" required placeholder="please leave comment here!"/>           </div>           <h4> name: </h4>           <div>             <input type="text" class="comment-form form-control input-sm" name="author" ng-model="commentdata.author" required placeholder="name"/>           </div>           <div>             <button type="submit" class="btn comment-button button-style intro-social-buttons">submit</button>           </div>           <!--<textarea class="comment-form" ng-model="cmtctrl.comment.body" cols="30" rows="6" required></textarea></br>           <label for=""> <h4>name:</h4> </label></br>           <input class="comment-form" type="text" ng-model="cmtctrl.comment.author" required placeholder="name"/></br>           <input class="btn comment-button button-style intro-social-buttons" type="submit" value="submit"></br>-->         </form>         <ul>           <li ng-repeat="comment in post.comments">             "{{comment.body}}"             <cite>- <b>{{comment.author}}</b></cite>           </li>         </ul>       </div>     </div>   </div> 

also, note use mongoose , schema allows body, author , date. made nested array within blog database wanted attached individual blog post.

let me know if there else can answer or give other files.

thanks


Comments

Popular posts from this blog

c# - Can I intercept a SOAP response in .NET before a content type binding mismatch ProtocolException? -

python - Terminate a gnome-terminal opened with subprocess -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -