change classes with angularjs

1

I need to change the style of an element when it is clicked and if it clicks it returns to the color it was in (like an "advanced search"). I have the following code:

<a href="" class="corCinza" ng-click="exibirForm = !exibirForm">...</a>
<div class="filtro" ng-show="exibirForm">
    <form ... /> 
</>

When I click on <a> it has to stay with corAzul and open the div with the form. If I click again it closes the div of the form and returns the shape. The form is already working, but I could not change the color. I tried using ng-class as a "tutorial" but it did not work. Can someone help me? P.S .: I only "program" html and css. The most I coded was a simple helloWorld in JS.

    
asked by anonymous 27.01.2016 / 21:15

1 answer

1

You can use ng-class working with condition by changing the element class. Example:

<a href="" class="corCinza" ng-class="{'corAzul': !exibirForm}" ng-click="exibirForm = !exibirForm">

When exibirForm is false , the corAzul class will be added.

You can also use with more than one class definition, if you want to remove the existing class, for example:

<a href="" ng-class="{'corCinza': exibirForm, 'corAzul': !exibirForm}" ng-click="exibirForm = !exibirForm">

In this way it only displays one class at a time.

    
27.01.2016 / 21:22