ngAnimateSwap - animations do not function as intended when boolean expressions are utilized

I adapted the original ngAnimateSwap demonstration from the AngularJS documentation to utilize a boolean expression for triggering the slide animation.

Initially, I anticipated the banner to switch back and forth between 'true' and 'false'. However, only the 'true' state is displayed while 'false' does not appear. According to the Angular docs, "ngAnimateSwap is an animation-oriented directive that allows the container to be removed and entered whenever the associated expression changes." Therefore, I assumed switching between true and false would animate the container.

The HTML code snippet looks like:

<div class="container" ng-controller="AppCtrl">
    <div ng-animate-swap="abool" class="cell swap-animation" ng-class="colorClass(abool)">
      {{ abool }}
    </div>
  </div>

In the controller:

$scope.abool = false;
$interval(function() {
  $scope.abool = !$scope.abool
}, 1000);

$scope.colorClass = function(abool) {
  return abool ? 'red' : 'blue';
};

To view the example in action, check out this Plunker: http://plnkr.co/edit/iKE5BekgpxOqX1YE952Z?p=preview

For further experimentation, updating the Plunker to toggle between 1 and -1 instead of true and false results in the expected animation - sliding between 1 and -1.

Answer №1

By setting the variable abool to the boolean value of false, Angular assumes that you do not want to interpolate {{abool}}.

To accomplish what you are aiming for, you need to convert the boolean value to a string.

var abool = false;
$interval(function() {
  abool = !abool;
  $scope.abool = abool.toString();
  $scope.colorClass = abool ? 'red' : 'blue';
}, 1000);

In addition, using ng-class is not necessary. A simple interpolation would work just fine:

<div ng-animate-swap="abool" class="cell swap-animation {{colorClass}}">
   {{ abool }}
</div>

See it in action on this plunker.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Automatically reload a particular webpage upon closing a pop-up window (using jQuery)

I am facing an issue with a pop-up named PopUp1 on page0.aspx. The problem occurs when a user clicks on a row in the GridView within PopUp1, causing another pop-up to launch, loading my page1.aspx. The complication arises when the user navigates through l ...

Creating a custom ID for a Firebase POST request

Is it possible to assign a custom ID in Firebase when using the POST method? For example: { "users": { "user_one": { "username": "jdoe", "password": "123" } } } I'm currently working on a Vue.js project and I want to save ...

What is the proper way to notify a caller of a rejected call?

index.js async handleCallActions() { const tokenResponse = await this.generateTokenForChannel(this.agoraChannel); this.initializeAgoraSDK(tokenResponse.data.appID); this.joinRoomWithToken(tokenResponse.data.token, this.ag ...

The Firefox extension is unable to activate any click events

Currently, I am developing a Firefox add-on with the goal of automatically filling in login form fields and submitting the login. For each website, I have access to various identifiers such as ids, classes or xpath, depending on what is provided by the web ...

How to Extract Minutes in Datatables Timestamps and Apply Custom Styling

Working with Datatables v1.10 Right now, my table is showing a date in the second column in the format 17-04-2019 14:34, which is how it's stored in the database. The filtering and searching functionality are all working as expected. The current HTM ...

What is the best way to extract text/html that appears between two consecutive <input> tags?

Is there a straightforward method to extract the text or HTML content located between input tags, even though these tags do not require closing tags? For instance, in the example below, I am looking to retrieve <b>Bob and Tim</b><br>Tim & ...

Locate MongoDB documentation pertaining to arrays of objects with two specific fields

For instance, consider a Mongo db collection: [ { "user_id": 1, "lead_id": 901, ... ... }, { "user_id": 2, "lead_id": 902, ... ... }, { "user_id": 2, & ...

What is the best way to conceal a canvas or another item?

Within my main canvas, there are three smaller canvases and a text element. <canvas id="Background" width="350" height="300" style="border:6px solid black; position: absolute; left: 10px; top: 10px;"> </canvas> <canvas id="Canvas1" width ...

Tips for invoking a Laravel Model function with a parameter in a Vue.js template

I'm facing an issue with displaying stock quantities for products in a Vue.js template. I have a product table and stock table where data about product sale and purchase are stored. I need to calculate the stock of each product based on purchase and s ...

Exploring various ways to implement HTTP GET requests within the PrimeVue DatatableUsing a mix

I am facing a challenge where I need to use different GET requests to populate my Datatable with data from separate tables in the Database. Despite trying different approaches, I am unable to figure out how to make this work successfully. I have realized t ...

I could really use some guidance on how to begin with the Node.JS app file in BlueMix

After delving into JS tutorials, I feel comfortable with the syntax and approach. Now, my focus is on utilizing Node.JS to develop an app using BlueMix. While I consider myself proficient in Java, web programming is uncharted territory for me, leaving me s ...

Is there a way to apply the style property only when a component is hovered in Next.js?

I would like the ability to hover over a component and have it display with unique CSS characteristics. For instance, if I hover on item A, I only want item A to stand out from the rest. Currently, I am using this method of changing the element's bac ...

unable to display loading image prior to upload

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html lang="en"> <head> <title>Unique Prints</title> <meta charset="utf-8"> <meta name="viewport" conte ...

Angular - Manipulating the selected option in a select box from the controller

My issue involves a select box that is defined in the following manner: <select ng-model="selectedSupplier" ng-options="supplier.name for supplier in suppliers"> </select> Within my controller, there is a button that doesn't have any r ...

Determine the presence of an image by using a wildcard in the URL

I need to show an image, and if it doesn't exist I want to display a default image. The challenge is that the image can come with any extension. Can someone suggest how I can modify the $.get() function in the code snippet below to make it search for ...

The node-vibrant module in combination with React

Hey there, I'm currently attempting to display the hex color of a react Component using node-vibrant. (The node package is already installed) It works perfectly when executed with node from the console. |- file.js |- image.jpg file.js // I am havi ...

There seems to be a complete absence of rendering in this particular vue

Upon initializing a fresh Vue project using Vue CLI 3 and removing all default views and components, I proceeded to add two new views. To my surprise, these views did not render when changing the URL; instead, I was met with a blank page and no error messa ...

What is the method for entering text into alerts with Protractor?

Attempting to access a webpage with a login alert requesting credentials. My search for how to switch to the alert box online has proven fruitless. How do I enter the username and password? In my previous attempt to automate this page using Selenium WebDr ...

Tips for incorporating WinBox JS into Angular applications

I've been experimenting with the WinBoxJS JavaScript library, and I'm familiar with using it in plain JS. However, I'm now attempting to integrate it into my Angular project. Can anyone guide me on how to achieve this? https://www.npmjs.com/ ...

Leveraging the identical data synchronously within the same useEffect block

My task involves fetching data in two different ways and rendering it accordingly. Initially, I need to retrieve each item one by one and increment the count. Once that is done, I should fetch all the data at once and update the display. To achieve this, I ...