Issue: [ng:areq] The argument 'HelloController' is not defined as a function, it is displayed as undefined

Struggling to integrate Angular with Django has been quite a challenge for me. After finally managing to make it work, I encountered yet another error. Each time I load the application, the following error message pops up:

Error: [ng:areq] Argument 'GreetingController' is not a function, got undefined

I've explored various solutions on Stack Overflow to no avail.

The snippet of my Angular code saved as app.js is as follows:

var app = angular.module('ABC',['ngRoute', 'ui.bootstrap']).
controller('GreetingController', ['$scope', function($scope) {
    $scope.greeting = 'Hola!';
}]);


app.config(function($interpolateProvider, $routeProvider){
    //$interpolateProvider.startSymbol('[[');
    //$interpolateProvider.endSymbol(']]');

    $routeProvider.when('/about', {
            templateUrl: 'views/about.html'
    }).when('/login',{
            templateUrl: '/views/login/login.html'
    }).otherwise({
            redirectTo: '/about'
    });
});

And here's my HTML snippet:

{% load staticfiles %}
<!DOCTYPE html>
<html>
    <head>
            <link rel="stylesheet" href="/assets/js/bower_components/bootstrap/dist/css/bootstrap.css">
            <link rel="stylesheet" href="/assets/style/main.css">
            <link rel="stylesheet" href="/assets/style/container.css">
            <link rel="stylesheet" href="/assets/style/button.css">

            <script src="/assets/js/bower_components/jquery/dist/jquery.js"></script>
            <script src="/assets/js/bower_components/bootstrap/dist/js/bootstrap.js"></script>
            <script src="/assets/js/bower_components/angular/angular.js"></script>
            <script src="/assets/js/bower_components/angular-route/angular-route.js"></script>
            <script src="/assets/js/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
            <script src="/app.js"></script>
            <script src="/views/login/login.js"></script>
    </head>

    <body ng-app="ABC">
            <div class="container-fluid">
                    <nav class="navbar navbar-default navbar-fixed-top navbar-inverse">
                            <ul class="nav navbar-nav">
                                    <li><a href="#home">Home</a></li>
                                    <li><a href="#login">Login</a></li>
                                    <li><a href="#signup">Sign Up</a></li>
                            </ul>
                    </nav>
            </div>

            <div id="wrap"  ng-controller="GreetingController">
                    <div class="container-fluid" id="main">
                            <ng-view></ng-view>
                    </div>
            </div>

     </body>
</html>

I would greatly appreciate any help in resolving this issue.

Here is the link to the source code.

Thank you in advance.

Answer №1

Modified a few elements and added the necessary components like bootstrap, etc. The URL for the file in routeProvider has also been updated. Take a look at the Plunker for more details.

HTML :

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e7f70796b727f6c30746d5e2f302a3066">[email protected]</a>" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
    <script src="https://code.angularjs.org/1.4.8/angular-route.min.js"></script>
    <script src="app.js"></script>
  </head> 

  <body>
            <div class="container-fluid">
                    <nav class="navbar navbar-default navbar-fixed-top navbar-inverse">
                            <ul class="nav navbar-nav">
                                    <li><a href="#home">Home</a></li>
                                    <li><a href="#login">Login</a></li>
                                    <li><a href="#signup">Sign Up</a></li>
                            </ul>
                    </nav>
            </div>

            <div id="wrap"  ng-controller="GreetingController">
                    <div class="container-fluid" id="main">
                            <ng-view></ng-view>
                    </div>
            </div>

     </body>

</html>

Angular code :

var app = angular.module('plunker', ['ngRoute']);

app.controller('GreetingController', function($scope) {
  $scope.greeting = 'Hola!';
});

app.config(['$routeProvider', function($routeProvider) {
    //$interpolateProvider.startSymbol('[[');
    //$interpolateProvider.endSymbol(']]');

    $routeProvider.when('/about', {
            templateUrl: 'about.html'
    }).when('/login',{
            templateUrl: 'login.html'
    }).otherwise({
            redirectTo: '/about'
    });
}]);   

Access the live demo on this Plunker link: http://plnkr.co/edit/sHvAOGD2zZVrWMb4NSr8

Answer №2

Your code isn't executing properly. It might help to move your

<script src="/app.js"></script>
tag to the bottom of the HTML file so that it runs after the DOM elements have been rendered.

{% load staticfiles %}
<!DOCTYPE html>
<html>
    <head>
      <link rel="stylesheet" href="/assets/js/bower_components/bootstrap/dist/css/bootstrap.css">
      <link rel="stylesheet" href="/assets/style/main.css">
      <link rel="stylesheet" href="/assets/style/container.css">
      <link rel="stylesheet" href="/assets/style/button.css">

      <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src="/assets/js/bower_components/bootstrap/dist/js/bootstrap.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.js"></script>
    </head>

    <body ng-app="ABC">
      <div class="container-fluid">
        <nav class="navbar navbar-default navbar-fixed-top navbar-inverse">
          <ul class="nav navbar-nav">
            <li><a href="#home">Home</a></li>
            <li><a href="#login">Login</a></li>
            <li><a href="#signup">Sign Up</a></li>
          </ul>
        </nav>
      </div>

      <div id="wrap"  ng-controller="GreetingController">
        <div class="container-fluid" id="main">
          <ng-view></ng-view>
        </div>
      </div>

     </body>
</html>

<script>
var app = angular.module('ABC',['ngRoute', 'ui.bootstrap']);

app.controller('GreetingController', ['$scope', function($scope) {
    $scope.greeting = 'Hola!';
}]);


app.config(function($interpolateProvider, $routeProvider){
    //$interpolateProvider.startSymbol('[[');
    //$interpolateProvider.endSymbol(']]');

    $routeProvider.when('/about', {
      templateUrl: 'views/about.html'
    }).when('/login',{
      templateUrl: '/views/login/login.html'
    }).otherwise({
      redirectTo: '/about'
    });
});
</script>

<!--script src="/app.js"></script-->
<script src="/views/login/login.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

Clear the local storage once the URL's view has been fully loaded

When retrieving details of a specific item by passing URL parameters stored in local storage, I encountered an issue. I need to delete the local storage variables after the view is loaded. However, what actually happens is that the local storage variable ...

Find the flowplayer when the page loads

Is there a way to make a flowplayer seek at the page load without it resetting? I've tried this: $(document).ready(function() { $f(0).seek(5); }); also tried: $(document).ready(function() { while(!$f(0).isLoaded()) { $f(0).seek(5); } }); ...

retrieve the data-initial-value's value through JavaScript

Hello, I am currently attempting to retrieve the text from this input field but all I'm getting is an empty value. <input type="text" class="quantumWizTextinputPaperinputInput exportInput" jsname="YPqjbf" autocomplete= ...

Tips on improving a function that verifies the existence of an image used as a CSS background to output a boolean value

I have encountered a challenge while working on a react file-upload component. The issue at hand is relatively simple - I aim to display an icon corresponding to the file extension for each uploaded file. These icons are loaded through css as background im ...

Programmatically setting properties for elements

I have a question about how to programmatically add a prop to a component in my React project. Here is the scenario: In the render() method, I have the following code snippet: <TextField name="password" va ...

Can anyone tell me how to retrieve the value of {{org}} in this situation?

<head> <title>My Unique Page</title> </head> <body> <input type="text" ng-model="selectedOrg" ng-show="!isSuperAdmin" readonly /> <select id="nameOrg" ng-model="selectedOrg" ng-cha ...

Having trouble with Discord.js version 12 and the messageReactionAdd event not triggering properly?

client.on('messageReactionAdd', (reaction, user) => { console.log('If you see this I actually work...'); }); I am having some trouble with my code. Despite setting up a simple console log, it seems like the code is not running prope ...

Having trouble fetching information from a JSON file stored in a local directory while using Angular 7

I am currently experiencing an issue with my code. It works fine when fetching data from a URL, but when I try to read from a local JSON file located in the assets folder, it returns an error. searchData() { const url: any = 'https://jsonplaceholde ...

Canvas ctx.drawImage() function not functioning properly

I've encountered an issue while trying to display images in a canvas using my rendering function. Here is the code snippet: function populateSquareImages(){ for(var i = 0, ii = squares.length; i < ii; i++) { if(squares[i].hasImage) { ...

Struggling to construct a binary tree as my descendants are not arranged in the right sequence

I am currently working on building a binary tree using PHP, MySQL, and a jQuery plugin developed by Frank-Mich. Here is the progress I have made so far... DATABASE STRUCTURE CREATE TABLE IF NOT EXISTS `members` ( `id` int(11) NOT NULL AUTO_INCREMENT, ...

Handling scroll events in a functional component using React

I'm having trouble understanding why the onScroll function isn't triggering the console.log statement. <table className="table" onScroll={()=>{console.log("Works")}> The console.log just doesn't seem to be exec ...

Tips for implementing mixins in a Nuxt.js application using the nuxt-property-decorator package

Recently, I worked on a project where I utilized Nuxt.js with TypeScript as the language. In addition, I incorporated nuxt-property-decorator. I'm currently trying to grasp the concept of the 'mixins' property in the code snippet below: mi ...

Master the art of animating ng-view transitions with AngularJS

I have 2 distinct HTML pages, namely welcome.html and login.html. These two pages are incorporated or "inserted" into a common page called index.html through the utilization of an exclusive attribute known as ngview, together with a router provider. This i ...

Is there a way to stop the dropdown from automatically appearing in a DropDownList?

Seeking a solution to use a custom table as the dropdown portion for a DropDownList in my project. My goal is for users to see the custom table when they click on the DropDownList, rather than the default dropdown menu. I expected to be able to achieve th ...

best method for embedding javascript code within html (within a script tag)

In my quest to create dynamic HTML using jQuery and insert it into a specific div on my website, I encountered an issue. Specifically, I am attempting to generate an anchor element where both the href and label are determined by JavaScript variables. Here ...

Transitioning from a traditional CURL method to utilizing AJAX and XMLHttp

I'm currently facing a challenge converting the curl code from an API named TextRazor to AJAX XMLHttp due to limitations on the platform I am working with. Despite trying various solutions shared by the community, I have been unsuccessful in retrievin ...

Issues with Meteor-Angular 1.5 service functionality

I've been struggling to develop a code-sharing service between two different components in Meteor 1.3, but so far I haven't had much success. Trying to create and inject Angular 1 services just doesn't seem to be working. This is what my An ...

The Shopify storefront API's create cart mutation generates an HTML response when called

I recently started developing an e-commerce website using Next.js and Shopify's storefront API. I have successfully set up the connection and can list all the products from the API. However, I encountered an issue when attempting to add a product for ...

What is the method for accessing the value of variable "a" in the following code?

request(target, function (err, resp, body) { $ = cheerio.load(body); links = $('a'); $(links).each(function (i, link) { if ($(link).text().match('worker')) { var a = $(link).attr('href').toStri ...

What is the best way to transform React API data into props that can be utilized in different components?

I've been struggling with this issue for quite some time now, unable to understand how to manipulate the data in a way that allows me to use it in other components. Although I can display the data correctly, I'm advised to structure it within a f ...