Fernando Wessek Fernando Wessek - 3 months ago 12x
AngularJS Question

Show button if two values are equal

I'm finishing up an app of mine, which is a forum, and I need users to be able to delete their own topics.

So, In my "Topics List" template, I have successfully rendered the following code:

<body ng-app>
<button ng-show="estudante == 'admin'"></button>


<button ng-show="{{ request.user.username }}=='{{ topic.creator }}'">Remover Tópico</button>

This button should not be displayed if the values of topic.creator and request.user.username are not equal. However, ng-if, ng-hide and ng-show properly configured don't seem to have any effect.

Is there a way to get this to work? Am I missing something on the scopes topic? :)

Thanks in advance!


Using '' in both values or none is the same. The button is displayed if the value mismatches:



Try this:

<button ng-show="request.user.username == topic.creator">Remover Tópico</button>

In your controller you should have the values you wish to compare assigned to $scope something like this:

$scope.request.user.username = "some name";
$scope.topic.creator = "some name";