When refreshing the page, Angular 1.5.0 duplicates the root template while using UI GRID with ocLazyLoad. The error "$$animateJs is undefined" is displayed

I am currently using the following versions of libraries:

  • Angular, angular-animate both are v. 1.5.0
  • Angular UI Grid v. 3.1.1
  • ocLazyLoad v. 1.0.9
  • Angular ui router v. 0.2.18

The Error encountered is:

TypeError: $$animateJs is not a function
    at d (angular-animate.js:2141)
    at angular-animate.js:2131
    at h (angular-animate.js:3174)
    at Array.d.push.fn (angular-animate.js:3020)
    at c (angular-animate.js:423)
    at b (angular-animate.js:393)
    at angular-animate.js:3042
    at m.$digest (angular.js:16714)
    at m.$apply (angular.js:16928)
    at g (angular.js:11266)

This error occurs when I refresh the page containing UI Grid
and
UI Grid module is loaded by ocLazyLoad.


If I include UI Grid script in <'body'> everything works fine. It only happens when using ocLazyLoad.

Other pages function correctly. State changes also work fine. The issue occurs only during a refresh.
Whether it is F5 or Ctrl + F5

The strangest thing is that my root template appears to be duplicated

https://i.sstatic.net/B6VZX.png

UPDATE:

I have uploaded a sample of the project to GITHUB

So the initial state is $state without GRID

Switching between states works fine.
BUT
Reloading a page on grid state or changing from initial state to one with grid causes the entire template to be duplicated.
The culprit here seems to be angular-animate. Disabling it resolves the issue.

Thank you!

Answer №1

Have you considered checking out the network tab in your chrome dev-tools? The order in which things are loaded may be causing issues.

Upon examining some code in ui.grid, I came across a section that seems to be checking for ngAnimate in a rather dynamic way:

// A function to disable ngAnimate animations on an element
disableAnimations: function (element) {
  var $animate;
  try {
    $animate = $injector.get('$animate');
    // Additional info here: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
    if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
      $animate.enabled(element, false);
    } else {
      $animate.enabled(false, element);
    }
  }
  catch (e) {}
},

enableAnimations: function (element) {
  var $animate;
  try {
    $animate = $injector.get('$animate');
    // Additional info here: http://brianhann.com/angular-1-4-breaking-changes-to-be-aware-of/#animate
    if (angular.version.major > 1 || (angular.version.major === 1 && angular.version.minor >= 4)) {
      $animate.enabled(element, true);
    } else {
      $animate.enabled(true, element);
    }
    return $animate;
  }
  catch (e) {}
},

I'm not entirely sure why ui.grid is messing with animations, but I suspect it could be related to the loading order.

update: It appears to be a load-order issue. By loading ngAnimate with ocLazyLoad before ui.grid, the problem is resolved.

If you have included ngAnimate in LazyLoad, you will need to adjust your state's resolve to:

resolve: load(['ngAnimate', 'ui.grid', 'grid/GridController.js'])

Admittedly, this might not be the most efficient solution as it increases loading time when entering the grid-state. However, it is clear that the problem is related to the loading sequence.

update2: Another potential solution (assuming ngAnimate is always included):

In your router.config, consider using the following for the load function

function load(srcs, callback) {
    return {
        deps: ['$$animateJS', '$ocLazyLoad', '$q',
                function ($$animateJS, $ocLazyLoad, $q) {
                    ...
        }]
    };
}

Answer №2

I followed JanS's answer and this solution worked for me.

        .state('app.myroute', {
            url: '/my-route',
            title: 'My Route',
            controller: 'MyRouteController',
            controllerAs: 'myRoute',
            templateUrl: helper.basepath('my-route.html'),
            resolve : {
                ngAnimate : ['$$animateJs','$ocLazyLoad', function ($$animateJs, $ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'vendor/angular-ui-grid/ui-grid.min.css',
                        'vendor/angular-ui-grid/ui-grid.min.js'
                    ])
                }]
            }
        })

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

What is the rationale behind sending only one form?

Is there a way to send two forms with just one click? The first form uploads an image to the server, while the second form sends information to a database. However, only the "myform" seems to be sent. Any suggestions? <form action="uploadpic.php" met ...

Navigating to a form within an Angular-UI uib-tab

Is it possible to access a form within a uib-tab for validation purposes? To see an example, check out this plunker: http://plnkr.co/edit/8hTccl5HAMJwUcHEtnLq?p=preview While trying to access $scope.forminside, I found that it's undefined (referring ...

The HTML page is failing to call the function in the JavaScript application

I recently started taking a YouTube Javascript course on chapter 34 titled "Make start button work" Javascript tutorial My HTML, CSS, and Javascript files are all located in the same folder. I am using VS Code along with the Live Server extension for codi ...

When utilizing the header slot in v-data-table, an empty header row is unexpectedly appearing

Having an issue with adding an extra empty row when using the header slot in v-data-table from Vuetify2. Check out the codepen here: https://codepen.io/satishvarada/pen/rNBjMjE?editors=1010 Vue.component('pivot-table',{ data:()=>({ ...

Getting map data from Mapbox and displaying it on an HTML page

I have been working with Mapbox GL JS and successfully retrieved data in the console. However, I am facing issues when trying to display this data on an HTML page. Can anyone assist me with this problem? I specifically need the data inside mapdata to be sh ...

The best practices for utilizing getStaticProps with Firebase

I am completely new to Next.js and am struggling to make the getStaticProps function work properly. import firebase from '../firebase' export default function Home({ posts }) { return ( <div> <h1>All Posts</h1> ...

Using jquery, transform json data into html table format

As a beginner in the realm of coding, I am currently experimenting with extracting data from my json file and transforming it into an HTML table. My tool of choice is the Atom code editor, and I am attempting to use JavaScript, specifically jQuery, to it ...

The functionality of Bootstrap toggle ceases to operate properly following an AJAX content update

I am currently using AJAX load to fetch some content on my webpage. I am working with Bootstrap 3 and Bootstrap toggle. When the content is loaded, the Bootstrap 3 content functions properly (the panel-primary panel is clearly visible). However, the Bootst ...

Toggle Jquery feature will dynamically add the "required" attribute to the input field when the specified div is visible, and it will automatically remove the attribute when the div

I am new to using jQuery and I am facing an issue with my code. I want to make a checkbox act as a toggle with jQuery. When the checkbox is clicked and the toggle displays the div, I want to add the required attribute to the checkbox input. Similarly, when ...

Updating objects in Angular 8 while excluding the current index: a guide

this.DynamicData = { "items": [ { "item": "example", "description": "example" }, { "item": "aa", "description": "bb" }, ...

Chrome Extension for Extracting Data from Websites

I am in the process of developing my Google Chrome extension that needs to store a variable from another website by passing it over. Below is the snippet of code found in the script.js file of the website: var editorExtensionId = "extension"; & ...

Having trouble with sending POST data to server while trying to save to a JSON file using ajax and php

I attempted to follow the instructions from various stackoverflow posts, but it seems that my server is not acknowledging any incoming requests. I am certain that the client is sending the request because it can be seen in the Firefox debugger tool. Below ...

Translating a few lines of JavaScript into C#

I'm looking to convert some code from JavaScript to C#, but I'm having trouble grasping a certain section... function getHisto(pixels) { var histosize = 1 << (3 * sigbits), histo = new Array(histosize), inde ...

JSONP OpenWeather API

I've been trying to access and retrieve weather data from OpenWeather using their API, but unfortunately, I'm facing some difficulties in getting it to work. It seems like there might be an issue with the way I am fetching the JSON data. To quer ...

Front end authentication failed (Angular/Spring stack)

Link to my front end code: http://embed.plnkr.co/toe4XO/. I made adjustments to the authentication/service.js file, see below: 'use strict'; angular.module('Authentication') .factory('AuthenticationService', ['Base ...

Sharing state between two functions in React using Hooks

Coming from a background in Vue, I am struggling to comprehend how to conditionally show something when the HTML is fragmented into different parts. Imagine having this structure: import React, { useState } from "react"; const [mobileNavOpen, setMobi ...

Locate the highest and lowest values within a .json file

When working on a graph using d3.js, one key step is setting up the scales for the axis. The data for the graph is stored in a Json file with multiple arrays, each representing different regions and years: [{ "id" : "AustraliaNewZealand" , "year" ...

Obtaining response object when encountering 401 error in AngularJS

I am currently working with Angular 1.6.4, Express 4.15.2, and express-session. My goal is to identify whether a user is unauthorized to access a specific route by checking for the existence of the req.session.user parameter. If the user is not authorized, ...

What is the best way to transfer information from a layout to its children within the app directory of Next.js?

One scenario I encounter frequently is the need for a button in a layout to toggle something within the components it contains. For instance, you might have a notifications button in a fixed layout that triggers a side panel to open in the main application ...

Vue - Display components next to sidebar

Having an issue with the vue-sidebar-menu. The sidebar is appearing over the components instead of beside them. Here is a screenshot of the problem: https://i.sstatic.net/cVgI6.jpg <template> <div id="app"> <sidebar-menu :menu="menu" ...