I'm trying to make a simple app with Angularjs and MongoDB. I have some articles where it's possible to add a comment and display them.
The comments section is in a template defined on a Directive, who is himself in the Home template with another Controller.
To be clear (or maybe not?) : HomeTemplate [with MainCtrl] own a COMMENT element [with his directive].
Here is my directive
app.directive('Comment', function(){
return{
templateUrl: '/comments.html',
scope:{
post:'=datapost'
},
controller: ['$scope', 'posts', 'auth', function($scope, posts,auth){
$scope.isLoggedIn = auth.isLoggedIn;
$scope.addComment = function(){
if($scope.commentToAdd === '')
return;
$scope.isLoading = true;
posts.addComment($scope.post._id, {
body: $scope.commentToAdd,
author: auth.currentUser()
}).success(function(comment){
$scope.post.comments.push(comment);
});
$scope.commentToAdd = '';
$scope.isLoading = false;
};
}]
}
});
Auth & Posts directives are defined later
Here it's my MainCtrl where I'm supposed to trigger the event :
$scope.showComments = function(){
$scope.showingComments = true;
};
And here my HTML :
<div ng-show="showingComments =!showingComments">
<div comment datapost="post" ></div>
</div>