My code looks like this:
<div class="block-border"
data-ng-show="qty > 0">
xxx
</div>
I know there have been a lot of changes with Animation in AngularJS. Can someone tell me the easiest way for me to make it take 500ms to show and 50ms to hide the xxx when the value of qty changes. Note that I am using the very latest AngularJS.
If you want to fade in using ng-if as a boolean angular has some nice documentation here https://docs.angularjs.org/api/ngAnimate . I used ng-if for my fading purposes here's an example below:
form.html
form.css
The way this works is if you want to fade in a button with a different color or text and different text color you can fade in a button when the form is filled out and valid and the invalid button will fade out leaving only one button depending on the state of the form. Kind of a hack but it works and looks smooth. I had to set a delay using
.ng-enter-stagger
because loading the animations at the same time was causing the buttons to blink and jump and not animate smoothly. So in this case we let invalid button hide first then load valid button when form is valid and all input fields have been filled out correctly.I couldn't get the accepted answer to work, but the following did work (taken largely from this ng-nuggets post):
and then my HTML element which I wanted to fade in and out looked something like this:
As @MichaelNguyen mentioned, Bootstrap does appear to have a style already called
fade
, and we are using Bootstrap in our application, yet the above styles worked nonetheless. If you already have a style namedfade
, then change the name to something unique before using the above code.Reference angular-animate.js
Add ngAnimate as a dependent module:
Pick a name for your transition, for example 'fade', and then define the appropriate CSS classes based on the naming convention described in the documentation:
Add the class to your element:
Demo: http://plnkr.co/edit/HWi0FfDOsHeSOkcrRtN2?p=preview