Angular being called before being established

After spending a considerable amount of time working on AngularJS, I encountered an error stating that Angular is being used before it was defined. Despite watching several instructional videos and thoroughly reviewing the documentation, even with just the first line in the JS file, the error persists. In the index file, I have ensured that Angular 1.6.2 is called as the first file before anything else. This confusion arises from being told that it is being used before being defined.

Here is my HTML code:

<!doctype html>
<html ng-app="weatherApp">
  <head>

    <!-- Bootstrap 3 Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- AngularJS -->
    <script src="//code.angularjs.org/1.6.2/angular.min.js"></script>
    <script src="//code.angularjs.org/1.6.2/angular-route.min.js"></script>
    <script src="//code.angularjs.org/1.6.2/angular-resource.min.js"></script>
    <script src="app.js"></script>

  </head>
  <body>
    <h1>Hello, world!</h1>

      <div class="container">

          <div>
            <div id="web-api">
                <h1>test</h1>
            </div>
          </div>

      </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  </body>
</html>

And here is the corresponding JS code:

// MODULE - WEATHER
var weatherApp = angular.module('weatherApp', ['ngRoute', 'ngResource']);

weatherApp.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);

// ROUTING 
weatherApp.config(function($routeProvider) {
    $routeProvider
    .when('/', {
        templateUrl: 'home.htm',
        controller: 'homeController'
    })

});

weatherApp.controller('homeController', ['$scope', function($scope) {

}]);

weatherApp.controller('forecastController', ['$scope', function($scope) {

}]);

Answer №1

Have you set up a server environment for your project? It is important to run the angular routes under a server environment such as live-server.

Additionally, double check that the file extension for the html files is accurately specified in the routing configuration in app.js

Answer №2

Your CDN configurations seem to be incorrect. Consider using the following CDN links instead:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-resource.min.js"></script>

The official documentation suggests using these URLs for improved performance and faster loading times.

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

Using Vue to showcase the result of a form submission on a separate page

Working with a <form> in the context of vue has been successful as I am able to send the form data to the server, receive a JSON response, and print it on the console. However, my current challenge involves displaying this JSON response on a differe ...

Troubleshooting a JavaScript function's ineffectiveness when triggered by clicking an

What is causing the function to not work properly when I click on the "Rate me" button? function increaseValue(){ var rate = parseInt($("#rateme").value, 10); rate = isNaN(rate) ? 0 : rate; rate++; $("#rateme").value = rate; } <scr ...

Difficulty arising from implementing v-if as a filter within a v-for loop in Vue.js

I'm struggling a bit with setting up a conditional statement using v-if along with a loop using v-for in Vue. Here's what I have so far: <div class="row form-group" v-for="(article, key, index) in articles" :key="key" v-if="article.pubdate(fi ...

Creating a grid layout that activates an image when clicked using JavaScript

I've successfully implemented a gridview with an image column, but I'm looking to enhance the functionality. Specifically, I want to enlarge the clicked image and bring it into focus on the screen. I've managed to achieve this when the image ...

Learn the process of utilizing ng-class within ng-repeat to designate a specific class for individual iterative div elements

**On my homepage, I am displaying data retrieved from a MySQL database in cards. However, all the tags have the same color i.e. class="tag tag-pill tag-danger". To resolve this issue, I am using ng-class={{hos.class}} where class is a ...

Tips for safeguarding your passwords across diverse authentication methods

Exploring a new project idea, I am interested in supporting the SASL Mechanisms for authentication, particularly PLAIN and DIGEST-MD5. I am curious about how to securely store users' passwords when implementing these two authentication methods. When ...

Unable to invoke the setState function within the onSubmit handler of Formik

Every time I submit my form, I want to display an alert. I attempted to pass my state as a prop to the component, but it didn't work. Here's how my class state looks: this.state = { alert_variant: '', alert_heading: ...

How to initiate a click event with JavaScript through C# in a WebBrowser control

Can the click function be triggered from a C# application? Below is the code that defines the function: $('#connectbtn').unbind('click').attr('disabled', false); $('#connectbtn').bind('click', ...

Adjust the background color of children based on the parent's mouseover event

Seeking a solution to fill three bars with varying percentages: <div class="bars" style="width:0%; background-color: red;"> <span class="bar"></span> <span class="bar"></span> <span class="bar"></span> </ ...

The quirky behavior of JavaScript's Array.reduce

Here is a snippet of code: let data = [1, 2]; let newBody = {}; let newArray = data.reduce((acc, current) => { newBody.doc = current; acc.push(newBody); return acc; }, []); The resulting array is: newArray = [ { doc: 2 }, { doc: 2 } ] If I re ...

Using Mongoose and MongoDB to reference a different schema without using the default ObjectId reference

I have two different schemas in my current project. var carSchema = new mongoose.Schema({ id: { type: Number, unique: true, required: true }, make: { type: String, required: true }, model: { ...

Executing a Select Change in a React Application using CasperJS

Has anyone else encountered difficulties with this issue? I have a basic React page set up, with a simple component that renders a select element and triggers a callback function when the value changes. Here is the basic structure of the component: const ...

Hovering over a colored fragment of text using the textrange object triggers a mouseover event

Is it possible to highlight a specific fragment of text using text range or another approach? I have a text block, for example: <div id="test">abcdefghij</div> I have successfully used text range to highlight text in yellow color (as seen in ...

Troubleshooting EJS Relative Path Problem when Using "include" in an HTML Document

I'm encountering an issue with my "index.ejs" file... The current content of the ejs file: <!DOCTYPE html> <html lang="en" dir="ltr"> <!-- THIS SECTION IS FOR <head> TAG THAT WILL BE STORED INSIDE "so_ ...

What benefits does using blocking code offer compared to non-blocking code?

Currently, I am diving into the world of JavaScript and Node. The concept of asynchronous operations makes sense to me, as I can see how it greatly improves efficiency. However, I've noticed that some languages such as Ruby and Java are inherently bl ...

Getting request parameters within Model in Loopback can be done by accessing the `ctx`

common/models/event.json { "name": "Event", "mongodb": { "collection": "event" }, "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "http": { "path": "organizer/:organizer_id/events" }, "properties": {}, "va ...

Using iScroll without animation by using scrolltoelement on an iPhone PhoneGap application

I've been working on an iOS PhoneGap app that uses Backbone and some other libraries. To handle scrolling, I implemented iScroll which has been functioning properly. However, I encountered a problem with the following code snippet: events: { &apo ...

Filter items by nested properties in ngRepeat

Is it possible to filter a complex object with nested properties using the ng-repeat filter? Can we achieve this filtering with the ng-repeat filter provided out of the box? Data { Name: 'John Smith', Manager: { id: 123, Name: &a ...

The Front End API is unable to locate the Back End Endpoint

I am currently setting up an API call to test the functionality of my backend server. The front end is built using React, while the back end utilizes Node.js with express. The endpoint on the backend is quite simple: app.get('/', (req, res) => ...

The server is unable to process your request to /graphql

I've encountered an issue while setting up the GraphiQL API. I keep receiving the error message "Cannot POST /graphql" on both the screen and network tab of the console. Despite having similar boilerplate code functioning in another project, I'm ...