Search code examples
angularjsangularjs-ng-show

AngularJS - ngShow is not working


My view is written as follows:

<ul class="commentslist cf">
        <li class="cf" ng-repeat="(key,comment) in activity.comments">
          <div class="comment">{{comment.name}}
            <div class="buttons" ng-show="isPostedUser(activity.$id, key, currentUser)">
              <button class="btn btn-delete tooltip"
                confirmation-needed = "Are you sure you want to delete this activity?"
                ng-click="deleteComment(activity.$id,key)">
                <span>Delete this comment</span></button>
            </div><!-- buttons -->
          </div><!-- comment -->
        </li>            
</ul>

In my controller associated with this view, there is a function called:

$scope.isPostedUser = function(actId, key, user) {
var refComment = new Firebase(FIREBASE_URL + "users/" + $scope.whichuser + "/activities/" + actId +
  "/comments/" + key);
var commentObj = $firebase(refComment).$asObject();
commentObj.$bindTo($scope, "data").then(function() {
  return $scope.data.giver === user.$id;
});

};

The purpose of this function is to display the delete button only isPostedUser evaluates to true. I tested and it does evaluate to true, but it still does not display the button. Any idea why?


Solution

  • So I fixed it as follows:

    $scope.isPostedUser = function(actId, key, user) {
        var refComment = new Firebase(FIREBASE_URL + "users/" + $scope.whichuser + "/activities/" + actId + "/comments/" + key);
        var commentObj = $firebase(refComment).$asObject();
        commentObj.$bindTo($scope, "data");
        return $scope.data.giver === user.$id;
    };
    

    If anyone has any better solution, please let me know.