Angular.js is throwing an error at line 13708, stating: "Error: [ng:areq] Function 'homeController' is missing or undefined."

Encountered an issue while trying to reach HomeController (module controller). Upon clicking the "home" link, an error appeared in the console stating that "HomeController is not a function; undefined.

Could you advise on where I should register this controller? Thanks, Rahul

twoPageApp.js

 * Created by rahul on 9/24/2016.
 */
(function(){
        angular.module("twoPageApp",["ngRoute"])
            .config(function($routeProvider){
               $routeProvider
                   .when('/home',{
                      templateUrl:'/JS/twoPageAppJS/partials/home.html',
                      controller: 'homeController',
                      resolve:{
                           homeContent:['$http',function($http){
                               return $http.get('/homeContent.json');
                           }]
                       }
                   })
                   .when('/page_one',{
                        templateUrl:'/Js/twoPageAppJS/partials/pageOne.html',
                        controller:'pageOneController',
                        resolve:{
                            homeContent:['$http',function($http){
                                return $http.get('/pageOneContent.json');
                            }]
                        }
                   })
                   .when('/page_two',{
                       templateUrl:'/JS/twoPageAppJS/partials/pageTwo.html',
                       controller:'pageTwoController.js',
                       resolve:{
                           homeContent:['$http',function($http){
                               return $http.get('/pageTwoContent.json');
                           }]
                       }
                   })
            });
    })();

twoPageApp.Controller.js

       (function(){
    angular.module("twoPageApp").controller("tpaController",
        ['$scope',function($scope){
            $scope.name="this is twoPageApp js controller";
        }])
})();

module Controller (homeController.js)

    /**
 * Created by rahul on 9/24/2016.
 */
(function(){
    angular.module("twoPageApp",[]) //here is the change...
        .controller("homeController",['$scope','$rootScope','homeContent',function($scope,$rootScope,homeContent){

            $rootScope.stub={
                homeContent:homeContent.data
            };
            $scope.hello="rahul";
            console.log("raja");
        }]);
})();

home.jsp

[![<div ng-app="twoPageApp" ng-controller="tpaController">
    <div>
        <a href="#/home">home</a>
        <a href="#/page_one">page One</a>
        <a href="#/page_two">page Two</a>
    </div>
    <div ng-view></div>
</div>][1]][1]

Answer №1

Eliminate the need for the [] parameter when registering the homeController in the file homeController.js

angular.module("twoPageApp") // remove the [] parameter

Answer №2

The homeController must be registered in a similar manner as the tpaController controller. Although you have configured the $routeProvider to utilize the homeController for the /home URL, it has not been properly registered within the code.

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

Creating dynamic connections between Plain Old Java Objects (POJOs) and RESTful APIs through automated

I have a POJO class that requires me to access a RESTful web service using specific properties from the POJO as parameters. The challenge lies in not knowing the endpoint and its parameters until runtime. Essentially, the user will set up the endpoint, i ...

Tips for implementing owl carousel in Nuxt.REACT_UNITS_CODIFY

Is there a way to make the script function on every page without the need for these pages to be reloaded? I have the Owl Carousel script in my static folder, and I have already included it in nuxt.config.js as shown below: head: { title: 'title&ap ...

Tips on transferring information from Angular to Rails

I am quite new to Angular, having only started learning it a week ago. My query pertains to how data can be transferred from Angular to Rails. Essentially, I wish to store whatever is input into {{entry.name}} in Rails. Appreciate your assistance! & ...

I'm sorry, there seems to be a JSON error. The syntax is incorrect and it

I am facing a problem where I encounter an error when trying to post a JSON object. The error message reads: SyntaxError: JSON.parse: unexpected character Here is my JavaScript object: var $arr_data = { title: '', category: &apo ...

Why isn't data displaying in the AJAX RESTful client for Java?

I have created an HTML form that is supposed to display the only user I have in JSON format in an alert box when a button is pressed. However, it currently shows an empty JSON body. I have checked the REST class and the URL in the AJAX call, both of which ...

The FormidableJS form encounters parsing issues when submitted through AngularJS

I have encountered an issue while posting to a formidable form from AngularJS. The form does not parse, and I suspect it might have something to do with the lack of express.bodyParser(). Server-side: ... var form = new formidable.IncomingForm(); console. ...

Updating the data when session begins

I am having an issue with two PHP files (index.php & data.php). The first file sends data to the second file, which runs every second to display the data. However, the problem is that the data is not updating. Perhaps looking at the code will provide a be ...

activating a button following the selection of a checkbox

My code includes a submit button that is currently disabled. I am looking to enable it when the user clicks on the "I agree" checkbox using jQuery. Can someone assist me with this? My code is written in HTML, JavaScript, and jQuery. <input id="agree" ...

Is there a reason why I am unable to include a URL as a JSON element in the data attribute of an AJAX request?

I'm working on an ajax request where I pass data to the data property in this manner: var myData = { "ID": 123456, "Description": "Some description", "Name": "Product Name", "ImageUrl": "http://example.c ...

Retrieving a particular data point from a JSON file encountered an error: TypeError stating that list indices must be integers and

The API has generated the following JSON output { "list":[ { "dt": 1490791600, "temp": { "day": 58.26, "min": 39.65, "max": 67.37 } "weather": [ { ...

How can I ensure eventual access to an object created in a React componentDidMount function without utilizing a deferred in ES6 Promises?

Thank you in advance for any help. I am delving into the world of ES6 native promises for the first time after previously using Q or Angular's $q service. I encountered a situation where using a deferred would have been convenient, but I was surprise ...

Transferring information through AJAX to the current page using a foreach loop in Laravel 5

As a newcomer to ajax and laravel 5, I am eager to learn how to pass data with ajax to populate a foreach loop in laravel 5 on the same page. <div class="row" style="margin:3% 0px 0px 0px"> @foreach($warung_has_kategoriwarungs['i want pass ...

Converting SHA1 function from JavaScript to Python

Can you help with translating this Javascript code to Python? def sha1(str1, raw): hexcase = 0 chrsz = 8 str1 = utf16to8(str1) def utf16to8(str): out = "" len = len(str) i = 0 while i < len: ...

Unconventional JavaScript Variable Declaration

While going through some source code, I stumbled upon this peculiar variable declaration that has me a bit confused. let eventsEnabled : ?boolean = null; Can someone explain what exactly this means? You can find the source code here. ...

Troubleshooting: WordPress integration with PhoneGap not processing JSON data

I've been following a tutorial and I'm encountering some issues with the examples provided. Despite my attempts to run the examples, I am not seeing any results: app.html <!DOCTYPE HTML> <html> <header> <script src="https:/ ...

Can someone help me figure out where I'm going wrong with the JS ternary conditional operator

Looking to improve my JavaScript logic skills as a beginner. Appreciate any tips or feedback on the function and not just this specific question. I'm curious why the code outputs --> [3,5] function divisors(integer) { let divisors = [] for (le ...

Navigating Options with Ag-Grid: A Simple Guide

When using the Ag-Grid in conjunction with AngularJS, the main goal is to implement a filter for a column that includes specific choices. For instance, let's say there is a column labeled Status with possible values of valid and invalid. This column u ...

The Vue component fails to respond to updates in plugin data

I am currently working on implementing a feature where a component reacts to data changes in a custom Vue plugin. To achieve this, the plugin creates a new instance of a Vue object in its constructor: this._vm = new Vue({ data: { obj: null, stat ...

I am specifically looking to parse JSON data where the section is set to 2. However, when receiving a response, all JSON files are being

I have a response where I want to remove null cardviews. Specifically, I am trying to parse only JSON objects with the section == 2 condition. While this functionality works, my RecyclerView still displays null values beyond the array length. package com. ...

What could be the reason for event.stopPropagation() not functioning properly with a switch statement

Could you please explain why the function event.stopPropagation() is not working on the switch element? Whenever I click on the switch, it prints the console log for the switch. However, when I click on the surrounding area (row), it logs the row event in ...