Last Updated: May 30, 2016
·
2.285K
· ohmmho

Change content on click with AngularJS

If you need to change an element content, whatever it is: text or an icon, with AngularJS is super easy.

Just need to set a variable to change the condition:

#the variable (and can be the name you want)
    ng-model="collapsed" 
#change the condition on click :D
    ng-click="collapsed=!collapsed"

And magic happens like this:

<button ng-model="collapsed" ng-click="collapsed=!collapsed">
    <i ng-class="{'fa fa-angle-up':collapsed,'fa fa-angle-down':!collapsed}"></i> 
</button>