0


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>

Nitneq
  • 651
  • 10
  • 26

1 Answers1

1

I'm not too sure what your question here is but:

<div ng-show="showingComments =!showingComments">

should be

<div ng-show="showingComments">

=! is not a valid operator, and you're comparing the same variable to itself

use ng-show="showingComments" to show if true, or ng-show="!showingComments" to show if false

Andrew Donovan
  • 552
  • 2
  • 14
  • I used this syntax for other ng-show and it works. So I tried to do the same thing (I'm new to Angular). But the good news is that your answer works ! I feel like an idiot to not test this solution, because it's obvious... Thanks you – Nitneq May 11 '16 at 13:48
  • Glad i could help :) – Andrew Donovan May 11 '16 at 14:07