Reputation: 8075
Working on a follow feature and using this as the two buttons:
<button ng-show="{{project[0].is_following.length > 0}}"
class="button button-block button-balanced"
ng-click="followProject()"
type="submit">UnFollow
</button>
<button ng-show="{{project[0].is_following.length === 0}}"
class="button button-block button-dark"
ng-click="followProject()"
type="submit">Follow
</button>
On my API doing what It needs to, I can see the buttons switching between ng-show="true" and ng-show="false" as I follow / unfollow they switch between the buttons.
However, the buttons themselves do not hide / show. They just stay the same.
Where is my fault?
Upvotes: 1
Views: 441
Reputation: 38103
ng-show
and ng-hide
take Angular expressions. This means you don't need the {{curly braces}}.
Remove them and it will be fine.
The curly braces are used in Angular to do string interpolation - placing the value of some scope expression inside a string. So if something is expecting a string, such as in HTML or where an attribute value is treated as a string, then you use the {{curly brackets}}. Otherwise, if you are specifying a condition or expression which shouldn't be treated as a string, you should not use the curly brackets.
Upvotes: 2
Reputation: 1657
You are printing the value out of your expression. ng-show
needs the expression itself. Try this:
<button ng-show="project[0].is_following.length > 0"
class="button button-block button-balanced"
ng-click="followProject()"
type="submit">UnFollow
</button>
<button ng-show="project[0].is_following.length === 0"
class="button button-block button-dark"
ng-click="followProject()"
type="submit">Follow
</button>
Upvotes: 4