Error 0x800a1391 - JavaScript runtime: The object 'angular' has not been defined

In my controller.js file, I have the following code:

 var myController = angular.module('myApp.controllers', [])

The Services.js file contains this code:

 angular.module('myApp.services', [])

However, when I try to run my application, I encounter an exception with the code "var myController = angular.module('myApp.controllers', [])" throwing the error message: 0x800a1391 - JavaScript runtime error: 'angular' is undefined.

If anyone could kindly help me understand what is going wrong, it would be greatly appreciated :)

Also, here is the HTML code for my web app:

<!DOCTYPE HTML>
         <html lang="en">
         <head>
            <meta charset="UTF-8">
            <title>PathFinding.js</title>
            <link rel="stylesheet" href="./css/style.css" />
            <link rel="stylesheet" href="./lib/themes/jquery.ui.all.css" />
            <script src="./js/angular.js"></script>
            <script type="text/javascript" src="path/to/bower_components/pathfinding/pathfinding-browser.min.js"></script>
            <script type="text/javascript" src="./lib/raphael-min.js"></script>
            <script type="text/javascript" src="./lib/es5-shim.min.js"></script>
            <script type="text/javascript" src="./lib/jquery-1.7.2.min.js"></script>
            <script type="text/javascript" src="./lib/state-machine.min.js"></script>
            <script type="text/javascript" src="./lib/async.min.js"></script>
            <script type="text/javascript" src="./lib/ui/jquery.ui.core.min.js"></script>
            <script type="text/javascript" src="./lib/ui/jquery.ui.widget.min.js"></script>
            <script type="text/javascript" src="./lib/ui/jquery.ui.mouse.min.js"></script>
            <script type="text/javascript" src="./lib/ui/jquery.ui.draggable.min.js"></script>
            <script type="text/javascript" src="./lib/ui/jquery.ui.accordion.min.js"></script>
            <script type="text/javascript" src="./lib/ui/jquery.ui.slider.min.js"></script>
            <script type="text/javascript" src="./lib/pathfinding-browser.min.js"></script>
            <script type="text/javascript" src="./js/view.js"></script>
            <script type="text/javascript" src="./js/controller.js"></script>
            <script type="text/javascript" src="./js/Services.js"></script>
            <script type="text/javascript" src="./js/mainApp.js"></script>

            <script type="text/javascript" src="./js/panel.js"></script>
            <script type="text/javascript" src="./js/main.js"></script>
         </head>
         <body>
            <ion-modal-view>
               <ion-content>
                  <ion-scroll zooming="true" overflow-scroll="false" direction="xy" style="width: 100%; height:100%;" 
                     scrollbar-x="false" scrollbar-y="false">

                     <div class="scroll-container" id="draw_area" style="width: 100%; height:100%; background: url('PathFindingMap.png') no-repeat ">
  
                     </div>
                  </ion-scroll>
               </ion-content>
            </ion-modal-view>

            <button style="margin-bottom:10px;margin-left:30px;margin-right:30px;" id="button1" class="control_button" type="button">Search!</button>

            <div style="visibility: hidden;" id="algorithm_panel" class="panel right_panel">

               <div class="accordion">

                  <h3 id="astar_header"></h3>

                   <div id="astar_section" class="finder_section">

                  </div>
               </div>
           </div>
          <div style="visibility: hidden;" id="play_panel" class="panel right_panel">

          </div>
          <div id="stats"></div>
        </body>
       </html>

Answer №1

The correct approach to building your angular app This is how you should define your module

var myApp = angular.module('myApp',[])

This is how you should add your controller in your controller.js Since you have already defined your module, there is no need to specify dependencies

var myApp = angular.module('myApp')
myApp.controller('myController', function(){
// Your controller content goes here
})

Here is how you should add your service in service.js

var myApp = angular.module('myApp')
myApp.service('myService', function(){
// Your service content goes here  (this.method);
})

Your code may be producing errors because you are defining your module twice and specifying its dependency []

Answer №2

If you're working on your controller.js file, be sure to reference the angular.js script within it.

All you have to do is drag the angular.js script into your controller.js file. Your code snippet should resemble this:

/// <reference path="../../../scripts/angular.js" />

Now, when it comes to your html code, make sure you include the angular.js script at the top level and then add your controller.js. Otherwise, your code may not function as intended.

<script src="scripts/angular.js"></script>
<script src="scripts/controller.js"></script>

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

The one-way binding feature in Angular directives is functioning properly, however, the two-way binding is not operational

My controller does not use scope because I use controller as etc. I have tested that Plunker works without scope One-way binding is functioning correctly However, two-way binding is not working as expected and shows a literal value HTML page is WORKING ...

What is the process of extracting data from a variable and inserting it into a JSON object in JavaScript?

I have just started learning about JSON and am currently working on a JavaScript program. I've been searching for a straightforward solution, but I may not be framing my question correctly. My goal is to allow users to input their information which w ...

Creating tabs in JavaScript using REST API after div elements have been generated

I found a great resource for creating tabs using JavaScript: The code provided in the link creates tabs based on the number of 'tab-content' divs within the 'tab-container'. In my current project, I am dynamically generating the ' ...

Managing JavaScript and AJAX requests in a single thread

Many believe that Javascript is a single-threaded language, while AJAX is considered asynchronous. Imagine this scenario; Let's say there is a button that, when clicked, triggers an AJAX call that takes 5-6 seconds to complete. Despite this, the UI ...

Transfer text input data using jquery to php, where it is processed and converted into json format. It is then necessary to dissect and interpret

I am encountering a problem where I keep receiving an undefined response and I feel completely lost, not knowing how to proceed... <!DOCTYPE html> <html> <head> <!--Jquery CDN--> <script ...

Having issues with jQuery AJAX not functioning correctly in PHP environment?

Can someone explain how Ajax and jQuery work together? I'm new to both technologies and I want to use Ajax to delete a row in my index.php file. <head><link rel="stylesheet" type="text/css" href="css/style.css"></head> <h1&g ...

What is the best way to display a landing page using an AngularJS web application?

As a newcomer to AngularJS, I am currently working on a small web application using ui-router for page routing. I have a landing page that consists of static content with clickable links covering the entire screen, while other pages only occupy the "ui-v ...

When the mouse is clicked, display the date field; and when a date is chosen,

I have a date displayed as plain text. When I click the 'change' button, a datepicker should appear below it. After selecting a date, the datepicker should be hidden and the date in the plain text should be updated accordingly. <span id="disp ...

Convert object to JSON format using AJAX request to a PHP file

Despite receiving a 200 green response, my data is still not getting written to the json file and it remains blank. The JavaScript: $(function() { $('form#saveTemp').submit(function() { let savdAta = JSON.stringify($('form#save ...

Tips for Modifying the Width of a Scrollbar

Is it possible to temporarily adjust the scrollbar width in Firefox or Internet Explorer while testing some layout code? I vaguely recall reading about this being tied to resolution, but I can't quite remember. I attempted changing the computer' ...

Tips for invoking the print function in a new window once the page has finished loading entirely

Hey there, I'm currently working on a piece of code where the main idea is to open a partial view in a new page and then call a print function for that partial view. I've managed to open a new window and call the print function, but unfortunately ...

Retrieving photos from database for dynamic display in Jquery Vegas Slideshow

I am currently integrating the Jquery Vegas Slideshow plugin into a project and I'm attempting to dynamically load images from my database directly into the slideshow script. Here is the code I have so far: <script type="text/javascript"> ...

The updating of Angular 2 CLI variables does not occur

As a complete newcomer to Angular 2, I recently attempted to start my first project using the Angular CLI. Unfortunately, I encountered some issues. It seems that the variables in my views are not updating as expected. I followed the typical steps: ng n ...

Mastering TypeScript: Leveraging Type Parameters in Generic Boundaries

"Utilizing Type Parameters within Generic Constraints" on the TypeScript website showcases the following example code. However, an error is thrown: 'Type 'U[keyof U]' is not compatible with type 'T[keyof U]'. Type 'U' ...

Is it possible to pass data into an AngularJS controller without relying on routes?

In my angular application, there is a controller that requires server-side initialization to happen before it is instantiated. I need this initialization process to be done synchronously so that the data can be fetched prior to the controller being called. ...

Slide your finger to adjust the location of a 3D model within the Three.js environment

Having trouble with a three.js example that allows me to rotate, zoom in, and zoom out a 3D object, but I can't figure out how to change its position by dragging. Any assistance would be greatly appreciated. Check out the example here. ...

I am currently working with a for loop within an object in JavaScript, but there seems to be a problem with one

Here is a function called validator: import validator from "validator"; import isEmpty from "is-empty"; export default function validate(data) { const errors = {}; for (const property in data) { console.log(property); //< ...

What is the best approach for fetching additional items using AngularJS?

After searching for a solution, I have come across the challenge of creating a "load more" button for elements from an array using Angular. In my case, I have 9 elements in an array which I loop through using ng-repeat, limiting the output to the first 3 ...

Encountering problems with encoding apostrophes in JavaScript within a Rails 5 environment

My issue involves an application that receives a response from JSON. The response includes text such as father's. Strangely, when I attempt to alert the response, it displays as father&#39;s. However, when I print the variable using the same JavaS ...

When attempting to add objects to an indexedDB object store, an InvalidStateError is encountered

I have defined IndexedDB and IDBTransaction dbVersion = 1; var db; var dbreq; var customerData = { ssn: "444", name: "Bill", age: 35, email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b0bbbebe92b1bdbfa2b3bcabfcb1bdbf"& ...