Manually initializing Angular bootstrap with async in the Angular script tag

I am encountering an issue when trying to asynchronously download the Angular script in my application and manually bootstrap the application upon loading. The error message states: Failed to instantiate module wt due to: Error: [$injector:modulerr] http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=y...) at Error (native) at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:6:416 at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:38:98 at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:7:322) at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:180) at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:349 The code I am using is as follows:

window.onload = function(){
  app = angular.module('wt', ['ngRoute']);
  app.config(function ($routeProvider,$locationProvider) {
      $routeProvider
          .when('/', {
              controller: 'homeController',
              templateUrl: 'template/home.html?ver='+file_version
          })
          .otherwise({ redirectTo: '/'});
      $locationProvider.html5Mode(true);
  });
  angular.module('wt').controller('homeController', function(){alert('Hello World');});
  angular.bootstrap(document, ['wt']);
}; 
For the script tags, I have included the following:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js" async></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route.min.js" async defer></script>
I would appreciate any assistance in identifying what might be causing this error. Thank you.

Answer №1

In case you wish to showcase the DOM prior to running any Angular operations, a simple solution is placing your scripts just before the closing </body> tag.

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

Utilize a single function to toggle the visibility of passwords for multiple fields upon clicking

Is there a way to optimize the function used to hide passwords for multiple fields when clicked? Instead of having separate functions for each field, I would like to have one function that is only active on the clicked button. For example, if the toggle ...

The A-Frame buffer geometry merger may cause unexpected entity shifts under certain circumstances

My A-Frame scene has a simple issue with the buffer-geometry-merger component. It works perfectly fine when entities are written in static HTML, but not when injected into the DOM using an A-Frame component. It seems like the geometry gets shifted, as if t ...

Implementing real-time time updates using php ajax technology

It's fascinating how websites can update the time dynamically without using ajax requests. I currently have a comment system in place. $('#comment').click(function(){ $.post(url,{ comment : $(this).siblings('textarea.#commen ...

Input information into the system from the successful response found on a different page

After receiving my ajax response successfully, I want to redirect to a new aspx page where there are 30 input type text controls. My goal is to populate all the values in those controls. How can I achieve this? Any suggestions? This is what I have attempt ...

The compatibility of ng-switch-when and ng-class

Is it possible to use ng-switch-when and ng-class together on the same element without any compatibility issues? I am facing some trouble dynamically changing the class of multiple elements simultaneously. It seems to only work on the currently displayed e ...

Display thumbnail images in jquery-ui dropdown menu

Hello, I'm looking to display a small image (the user's thumbnail) on the jquery-ui dropdown by making an ajax call. As someone new to ajax and unfamiliar with jquery-ui, I would appreciate some guidance in the right direction. Thank you! HTML/J ...

Tips for shifting a stuck div 200px upward once the bottom of the page is reached while scrolling:

I've set up a page layout with two columns, one fixed and the other scrollable. The left column is fixed (containing Google ads) and stays in place as I scroll down the page. The right column displays posts and scrolls along with the rest of the con ...

Steps for adjusting the matMenuTriggerFor area so it only triggers when hovering over the arrow

Hello there! I'm currently working on adjusting the trigger area for opening the next menu panel. Right now, the next menu panel opens whenever I hover over either the title or the arrow. However, my goal is to have the menu open only when I hover ove ...

Having trouble displaying images in Express JS

Here are the lines of code that I wrote in Express: res.write("The current temperature is "+temp+". "); res.write("Weather is currently "+weatherDes); res.write("<img src=" +imageURL+ ">"); res.send() ...

Updating the state of an object within a mapping function

I've been struggling with this issue for two days now. Despite my efforts to find a solution online, I am still stuck and starting to believe that I might be missing something. The main functionality of the app is to click a button and watch an apple ...

Executing Multiple AJAX Requests Sequentially with JQuery

Is there a way to ensure that ajax calls in jQuery are executed in sequence without using async: false? I have tried utilizing ajaxComplete but it has not resolved the issue. The code provided loops through elements in an array and fires off ajax request ...

javascript various backgrounds on click

I have implemented a list to allow users to select their top 3 choices, and I am using JavaScript to track these selections and change the background color accordingly. 1st selection -> Green background 2nd selection -> Yellow background 3rd sel ...

'this' in Arrow functions does not have a reference to the calling context

Something seems off about the context in this code. I've left comments to describe my issue below: const cat = { //arrow function meow: () => { console.log(this); }, makeMeow(){ // Why does 'this' refer ...

What could be the reason behind my inability to initiate this PHP file through jQuery/AJAX?

I'm experiencing an issue with a piece of PHP code (located at ../wp-content/plugins/freework/fw-freework.php). <div id="new-concept-form"> <form method="post" action="../wp-admin/admin.php?page=FreeWorkSlug" class="form-inline" role ...

Converting every item's values into keys

Currently, my goal is to export all object values as keys specifically for a tree-shakable import system in a plugin I'm currently developing. The approach involves dynamically importing modules from various directories and subfolders, consolidating t ...

What steps do I need to take in Bootstrap 5 to add a search icon to the navbar that reveals a search box beneath it when clicked?

I've made progress on the navbar design Now, I'm looking to add a search icon next to the login button. Clicking on the search icon should reveal a search box below the navbar, similar to the image shown below. My transparent navbar has a relati ...

When using AngularJS, the attribute type does not display properly if it is set to "text"

In my AngularJs application, I've encountered a peculiar issue related to rendering input fields with the type "text". Strangely, every time I try to include an input with type text, the type attribute seems to magically disappear. For instance: < ...

An issue occurred while attempting to retrieve an access token in NodeJs, resulting in 500 failures. The error message displayed was: "connect ECONNREFUSED" at process._tickCallback (node

I'm trying to authenticate users using Passport's GoogleStrategy, but I keep encountering the following error. Can anyone assist me? Code passport.use(new GoogleOAuth2Strategy({ clientID : configAuth.googleAuth.clientID, clientS ...

Changing the location of an ArcGIS map with a click event in a Vue application

I am attempting to dynamically update a map to display my current location using Vue. I have created an onClick event that updates the props and sends them to my map component. To trigger a re-render of the map component when the data changes, I am utilizi ...

Press the div using JavaScript and jQuery

Is it possible in JavaScript to automatically click on a hidden div once it is displayed? For instance, imagine we have a div with the style "display:none;" like so: <div style="display:none;" id="button">Hello World</div> Once this div&apos ...