I am developing an application (forecasts for tennis matches)

The final touch before launching the project, I want to add a "delete comment" button.

The button in HTML looks like this:

<button ng-show="" ng-click="deleteComment(comment)" class="glyphicon glyphicon-remove marginio"></button> 

An example of a comment with a button you can see by clicking on the link and selecting the forecast "Nadal R. / Verdasco F. vs Bolelli S. / Seppi A." (or themselves quickly register and pee comments anywhere).

I use Firebase's subd, and it turns out that each prediction (predictionId) has its own comments. And I need to make sure that the button is visible only to the user who added this comment. Here I am stuck.

Here is my code: https://github.com/NiR-IT/tennispredictions

service under the comments - scripts / services / comments.js
controller - scripts / controllers / browse.js

Closed due to the fact that off-topic participants Grundy , insolor , Nicolas Chabanovsky 26 Mar '16 at 7:11 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Grundy, insolor, Nicolas Chabanovsky
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • add the necessary code directly to the question. Links can only be a supplement - Grundy

1 answer 1

Logically, when authorizing a user in $rootScope must have user identification (his Id , userName ... someInfo ). When displaying comments, each comment will have the identifier of the person who created it, for example 5. You can (for simplicity) define the controller in $scope.authUserId = $rootScrope.User.getId() - this will for example return the identifier of the current authorized user. and on the button you will take (if you have ng-repeat="comment in comments" ) comment.userId and append to the ng-show directive.

It turns out something like this:

 <button ng-show="authUserId == comment.userId" ng-click="deleteComment(comment)" class="glyphicon glyphicon-remove marginio"> </button>