AngularJS - Unable to locate controller

I attempted to create a script that would load the necessary files for my AngularJS application.

However, I encountered an error when running the Angular.bootstrap portion of the script.

Detailed error information on the AngularJS homepage

The error occurs because AngularJS is unable to locate my masterController. I have verified that the module name and controller name match, so I am puzzled as to why it is unable to recognize the controller.

This is what my code looks like:

Index.html

<!doctype html>
<html ng-controller="masterController">
<head>
    <!-- META -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1"><!-- Optimize mobile viewport -->
    <meta name="author" content="Michael Tot Korsgaard">

    <title>Mythodea map explorer</title>

    <link rel="icon" type="image/png" href="favicon.png">

    <script src="lib/JQuery/1.12.3/jquery.min.js"></script>

    <script src="lib/AngularJS/1.5.5/angular.min.js"></script>
    <script src="lib/AngularJS/1.5.5/angular-animate.min.js"></script>
    <script src="lib/AngularJS/1.5.5/angular-aria.min.js"></script>
    <script src="lib/UI-Router/0.2.18/ui-router.min.js"></script>

    <script src="lib/moment/2.13.0/moment.js"></script>

    <script src="js/log.js"></script>
    <script src="js/build.js"></script>
</head>;

<body ng-cloak>
    <div ui-view></div>
</body>;
</html>;
;

core.js

var app = angular.module('AcademiaUnitate', [
        'ui.router',
        'ngAnimate'
      ]);
;

master.controller.js

angular.module('AcademiaUnitate')
.controller('masterController', function ($scope) {
});
;

build.js includes my Angular files added to the <head> tag

var buildStart = moment(),
    fileCounter = 0;
initialize();
function initialize(){
    loadJson('app')
        .done(function(response){
            var files = response.files,
                folders = response.folders;
            getFiles(files, 'app')
                .done(function(response){
                    getFolders(folders, 'app')
                        .done(function(response){
                            bootstrap();
                        });
                })
       });
}

function getFolders(folders, path){
    var deferred = $.Deferred();

    if(folders.length > 0){
       loadFolder(path + '/' + folders[0])
            .done(function(response){
                folders.splice(0, 1);
                getFolders(folders, path)
                    .done(function(response){
                        deferred.resolve(response);
                    });
            });
   } else {
        deferred.resolve(true);
    }

    return deferred.promise();
};

function getFiles(files, path){
    var deferred = $.Deferred();

    if(files.length > 0){
        loadFile(path + '/' + files[0])
            .done(function(response){
                files.splice(0, 1);
                getFiles(files, path)
                   .done(function(response){
                        deferred.resolve(response);
                    });
            });
    } else {
        deferred.resolve(true);
    }

    return deferred.promise();
};
function loadFile(src){
    var defer = $.Deferred(),
        fileType = src.substring(src.lastIndexOf(".") + 1, src.length);

    var head = $('head');

    fileCounter++;

    if(fileType.toLowerCase() === 'js'){
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = src;
        document.getElementsByTagName('head')[0].appendChild(script);
        defer.resolve(true);
    } else {
        defer.resolve(true);
    }

    return defer.promise();
};
function loadFolder(path){
    var defer = $.Deferred();

    loadJson(path)
        .done(function(response){
            var folders = response.folders,
                files = response.files;

            if(folders !== undefined){
                getFolders(folders, path)
                    .done(function(response){
                        if(files !== undefined){
                            getFiles(files, path)
                                .done(function(response){
                                    defer.resolve(response);
                                });
                        } else {
                            defer.resolve(response);
                        }
                    });
            } else {
                if(files !== undefined){
                    getFiles(files, path)
                        .done(function(response){
                            defer.resolve(response);
                        });
                } else {
                    defer.resolve(response);
                }
            }
        });

    return defer.promise();
};

function loadJson(path){
    var defer = $.Deferred();
    $.get(path + '/structure.json', function(response) {
        defer.resolve(response);
    });
    return defer.promise();
};

function bootstrap(){
    $(document).ready(function(){
        var bootstrapStart = moment();
        angular.bootstrap(function(){
        });
    });
};
;

The purpose of my build.js file is to locate the structure.json file, which specifies the js files to add to the <head> tag and then identify additional structure.json files in folders. Once this process is complete, Angular will be bootstrapped.

Answer №1

During the bootstrapping process of Angular, there is a missing file for the masterController function. It is important to include this file in order for the application to run smoothly. Please make sure to add the necessary file for proper functionality.

Answer №2

It is highly recommended to give your controller a more suitable name

angular.module('AcademiaUnitate')
  .controller('MasterController', function MasterController($scope) {

});

For the most up-to-date AngularJS controller documentation, visit https://docs.angularjs.org/guide/controller and see an example at https://docs.angularjs.org/tutorial/step_02

If all your Angular code resides in one file, you can consider: 1) placing the controller right after or within the angular module()

angular.module('AcademiaUnitate', [
    'ui.router',
    'ngAnimate'
]).controller('MasterController', function MasterController($scope) {

});

OR 2) utilizing the app variable

var app = angular.module('AcademiaUnitate', [
    'ui.router',
    'ngAnimate'
]);

app.controller('MasterController', function MasterController($scope) {

});

Answer №3

The reason your controller cannot be found is because you forgot to add core.js in your index.html file. Make sure to include it.

<script src="core.js"></script>

Answer №4

Don't overlook including ng-app="AcademiaUnitate". Simply update the code from

<html ng-controller="masterController">
to
<html ng-app="AcademiaUnitate" ng-controller="masterController">

Answer №5

After some investigation, I discovered the issue stemmed from the method of bootstrapping my application.

angular.bootstrap(function(){});

I needed to modify it to

angular.bootstrap(document, ['AcademiaUnitate']);

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

Once the Ajax request is finished, the cookie deletion function ceases to function

When the website loads, a cookie is generated using PHP before any other content or headers are sent. This is done with the following code: $steam_login_verify = SteamSignIn::validate(); if(isset($_COOKIE['userid'])) { //work with cookie va ...

Updating the user interface in react-apollo following a delete mutation

After successfully executing a delete mutation in my React Apollo component, the UI of my app did not update as expected. Here is the code snippet for reference: const deleteRoom = async (roomId, client = apolloClient) => { const user = await getUser ...

Identify when 2 sets of radio buttons are chosen using jQuery

I need assistance with a webpage that presents the user with two simple yes-no inquiries. Below each question, there are two radio buttons for selecting either yes or no. <p>Question 1: Yes or No?</p> <input type="radio" name="q ...

Trouble updating outside controller data while using AngularJS directive inside ng-repeat loop

I am currently working with a isolate scope directive that is being used inside an ng-repeat loop. The loop iterates over an array from the controller of the template provided below: <!DOCTYPE html> <html> <head> <link rel="sty ...

The functionality of the like button in Flask with jQuery/JSON seems to be malfunctioning

I am currently in the process of developing a small flask application and attempting to create a like button that can function without requiring a page refresh. After considering jQuery as a potential solution, I began writing some code. However, it appea ...

Showing headings in the table vertically

I have a header1 and header2 with corresponding data1 and data2 that I want to display differently. h h e e a a d d e e r r 1 2 data1 data2 To enhance the presentation, I wish to add borders around the head ...

What is the process for generating a tree structure from an HTML element?

This particular element is found within my Vue2 application: <div class="child-elements-container draggable-container"> <div> <div entity-type="entitytype1" type="elementType" id="2" class= ...

A helpful guide on passing a component as a prop to a child class and incorporating it within the child component along with additional props

Within my parent class, I have loaded a child class component and passed another component to it as a prop. In the childclass component, I am trying to display that component. <EditRecordModal show={this.state.showEditModal} onHide={this.handle ...

How can I prevent users from clicking the same link multiple times in HTML?

Is it possible to disable the href after one click using javascript or jquery? I need some assistance with this. Please help. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml ...

What could be causing the malfunction of the Google Maps iframe, preventing it from displaying the location properly

I am having trouble with this Google Maps iframe, it doesn't seem to display the location properly. Why is that? <iframe src="https://www.google.com/maps/place/18%C2%B045'14.7%22N+98%C2%B059'44.0%22E/@18.7540995,98.9933669,17z/data=!3m1! ...

Using jQuery Datatables: Storing the received JSON data into a variable

I have incorporated 2 plugins for my project: Datatables (used for pagination) Defiant.js (providing JSON search capability) Describing my issue along with the code snippet... $(document).ready(function() { var myjson; //Initializing Datatable ...

Leveraging the push method within AngularJS

Hello, I am currently working on setting up an eCommerce shop using Angular. Below is the code snippet I am using: var shopApp = angular.module('shopApp', ["slugifier"], function() {}); controllers.productController = function($scope,FetchFa ...

Is it possible to use async/await together with forEach in JavaScript?

Within my array of objects containing user information and emails, I aim to send emails using AWS SES. To accomplish this, I must decide between utilizing await or normal .then. Preferably, I would like to use await within a forEach loop. Is it feasible to ...

Using Q to conduct polling asynchronously with promises

I am facing a situation similar to the one discussed in this blog post: Polling with promises. The author explains using promises for polling until a JobID is returned. I intend to implement this using Q. I want to chain promises together but my attempts ...

The tooltip content is a little too narrow

I have successfully implemented QTip2 to display a tooltip: The content of the tooltip is generated in the following method: public string GetHours() { DateTime d = Convert.ToDateTime(Request.Form["date"]); Bump b = new Bump(); ...

Unlocking the potential of resizable bootstrap table columns in React

Currently utilizing a bootstrap table <div class="table-responsive"> <table class="table table-bordered"> <thead> <tr> <th>#</th> <th>Table heading</th> </tr> < ...

Executing PHP function through AJAX

I have thoroughly researched various resources regarding my issue but still have not been able to find a solution. My goal is to retrieve the result of a PHP function using jQuery AJAX. function fetch_select(){ val_name = $('#name').val(); ...

The onChange function does not seem to be functioning properly within the Reactstrap customized input switch

Here is some code: import { CustomInput } from 'reactstrap' ... const changeMediaStatus = (e) => { console.log(e) } ... <CustomInput type="switch" className="ml-auto mr-1" onChange={(e) =>changeMediaStatus ...

Is it possible to extract attribute names of a DOM object using angular.element? If so, what is the process? If not, is there another way to access this information within Angular?

Is it possible to achieve this? If so, how can we accomplish it? Here is what I have attempted: // Assuming domObj is a dom element var ngObj = angular.element(domObj); var attrNames = ngObj[0].attributes; For example, let's consider the following d ...

Prevent a form from loading depending on the response received from an ajax callback

I am currently working on implementing an ajax post function. The process involves sending data and receiving a callback from PHP with some data in return. Depending on the returned data, I need to make a decision whether to proceed or allow the user to re ...