Last Updated: May 30, 2016
·
2.633K
· 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>

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

AngularJS pages are long-lived browser apps with the same script risk as a newer single-page app. Third-party code in the template can read forms and values rendered on the page.

Security insights from Cside