Issue with ngAnimate in Angular 1.4 + TypeScript not functioning correctly upon initial page load

In Summary

At the start, the view fades in when using ES5 (ES5 Example)

The view does NOT fade in when utilizing Typescript import (Typescript and ES6 Import Example)


I am currently exploring Typescript, ES6 modules, and their integration. Most aspects work well, but I'm facing an issue with animating the ui-view using ngAnimate. When using ES6 modules and the import statement, it appears that dependencies are lazy loaded, causing ngAnimate to not function during the initial page load. However, once the page is fully loaded, the animation works as expected when transitioning views.

To demonstrate this behavior, I have created two Plunkers - one with an app in plain ES5 and another with a Typescript setup using SystemJS and imports for dependencies.

Here is the ES5 example. Upon running this Plunker, you will observe the view fading in at the beginning. This effect is achieved by including files via script tags in the index.html file, with animations defined in CSS:

ui-view.ng-enter {
  animation: fadeIn .5s ease both;
  animation-delay: .3s;
}

ui-view.ng-leave {
  animation: fadeOut .5s ease both;
}

Here is the Typescript example. You may notice that the view doesn't fade in, despite utilizing the same animation structure. The difference lies in the usage of Typescript and ES6 modules imported via import. It seems that with import, ngAnimate may not be fully or immediately loaded, possibly due to lazy loading.

I'm keen on getting this technology stack to work seamlessly, as it offers a more enjoyable and modern development experience. Any suggestions?

Answer №1

Through thorough investigation and assistance from a member of the Angular team, I discovered that ngAnimate initially disables all animations for the first two digests by default when loading. This means that if it detects any remote assets being downloaded, it will wait until they are fully loaded. This is particularly noticeable when using Typescript / ES6 modules. To ensure that all animations run during bootstrap even while remote assets are downloading, a workaround involves creating a directive to enable animations using $animate.enabled(true);. This directive can be placed on either the body or html tag. In the provided Plunker above, I have implemented the directive on the body tag. Here is the code snippet:

<body allow-animations-on-load>
  <ui-view></ui-view>
</body>
app.directive('allowAnimationsOnLoad', ['$animate', function($animate) {
  $animate.enabled(true);
}]);

The corresponding Plunker has also been updated. Now, as shown in the example, the animation smoothly fades in during bootstrap.

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

Error caused by a null injector when sharing an Angular module that contains different @angular/material modules

My uiModule is set up to import and export various @angular/material modules. I was expecting that by importing uiModule into anotherModule, anotherModule would have access to the @angular/material components. However, this doesn't seem to be working ...

Angular login/signup modal/dialog component for seamless user authentication

Currently, I am working on adding a login/signin dialog to my app similar to the one used by Medium. After doing extensive research online, I have decided to use the $modal from angular ui-bootstrap for this. Can anyone please recommend a tutorial that wil ...

I am in the process of transitioning my JSX website to TSX and am struggling to figure out the proper placement of my type definitions

As the title suggests, I am in the process of migrating an application that I developed using the Google Maps API for rendering maps. In this app, I display information on maps and include functionality to zoom in when a user clicks on something. The erro ...

Assigning a value to an Angular class variable within the subscribe method of an HTTP

Understanding the inner workings of this process has been a challenge for me. I've come across numerous articles that touch on this topic, but they all seem to emphasize the asynchronous nature of setting the class variable only when the callback is t ...

Instructions for activating a button in the absence of any inputs

I need help enabling a button in angularjs based on whether any of the inputs are filled out. I was successful in disabling a button when only one input is checked, but how can I do this for all inputs affecting one button? This is what I've attempted ...

Ways to verify if a value corresponds to a particular data type

Is there a more elegant way for TypeScript to check if a value matches a specific type without actually invoking it, instead of the method described below? Consider the following example: import { OdbEventProcessorFunc } from "./OdbEventProcessor&quo ...

Angular 4: Issue with Radiobutton values vanishing when another Radiobutton is selected

I have 3 radio buttons that are used to sort different data from an API. However, when I press one radio button, the value of the selected button disappears if another radio button is clicked. This issue can be seen in the screenshots here: https://i.sstat ...

When the user clicks, show a designated search result in a separate container

I've been developing my Angular cocktail application, and I've reached a point where I can display all the cocktails in my database (only showing names). Now, I want to implement a feature where if I click on a specific cocktail, its full content ...

Having difficulty authenticating Slack requests

I'm currently working on a project to develop a Slack bot using the events API for an experiment at my job. I am facing challenges in verifying the request and can't seem to pinpoint where I'm making a mistake. The bot is being built using ...

What is the process for creating the AngularJS documentation?

I find the documentation for AngularJS to be easily understandable - I wonder how it is created? If JSDoc is used, where can I find the style sheet? ...

What strategies can I use to refactor this controller in Angular 1.5 to make it more concise and efficient

I am encountering an issue with a component I have that contains a button. Whenever the button is clicked, it triggers one of two backend services depending on where the component is located. To achieve this, I am currently passing a flag to the component ...

Confirm the existence of a non-null value

One of the functions I have implemented is designed to remove null values from an array that is passed as input. This function also provides an optional transform functionality, allowing the user to modify the elements of the array into a custom format if ...

Can an interface be designed to have the option of containing either one property or another?

I am in need of an interface that resembles the following structure: interface EitherOr { first: string; second: number; } However, I want to make sure that this interface can only have either the property first or second. Do you think achieving this ...

Vue.js - Prop validation error: The prop "page" expects a value of type DocumentPageDto, but received an Object instead

My component PageViewer has props defined like this: props: { page: DocumentPageDto, }, I'm using it in another Vue component like this: <div><PageViewer :page="selectedPage"></PageViewer></div> The value of ...

The `$refs` variable in Vue can be used to reference a specific Vue component within a class-st

Would it be possible to access this.$refs.label? I am using the package vue-property-decorator. Below is the content of the component: <template> <div> <label ref="label">asd</label> </div> </template> <scr ...

Interface for TypeScript hashmap/dictionary

I am currently working on incorporating a hashmap/dictionary interface. The progress I have made so far is as follows: export interface IHash { [details: string] : string; } I am facing difficulties in comprehending the exact meaning of this syntax. I ...

Issues with react-router-dom's <Routes> and <BrowserRouter> components

Encountering an issue with <Routes> while using react-router-dom. The code in my index.tsx file is as follows: import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './Ap ...

The compilation of @types/socket.io-redis fails because it cannot locate the Adapter exported by @types/socket.io, which is necessary for its functionality

It seems like there may be an issue with my tsconfig file or something similar. npm run compile > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c69626b6562694c3d223c">[email protected]</a> compile /User ...

The Unhandled Promise Rejection Warning in mocha and ts-node is due to a TypeError that arises when attempting to convert undefined or null values

I've been encountering issues while setting up ts-node with mocha, as the test script consistently fails. I attempted to run the following commands: mocha --require ts-node/register --extensions ts,tsx --watch --watch-files src 'src/**/*.spec.{ ...

Encasing event handler callback within Observable pattern

I am currently exploring how to wrap an event callback from a library to an RxJS Observable in a unique way. This library I am working with sets up handlers for events like so: const someHandler = (args) => {}; const resultCallback = (result) => {} ...