The ng-view directive in AngularJS 1 seems to be malfunctioning

I currently have a project using AngularJS 1.

I am facing an issue with rendering HTML files using ngRoute. The problem lies in the app.js file where the app.config() method is not executing properly, causing the content inside ng-view to not display. Strangely, no errors are being thrown either.

Could someone offer assistance with this?

index.html

<head>
    <title>Apollo</title>
    <meta charset="utf-8" />

    <!-- Other meta tags and stylesheet links omitted for brevity -->

    <script src="public/lib/angular.min.js"></script>
    <script src="public/lib/angular-route.js"></script>
    <script src="app.js"></script>
    <script src="src/controllers/HtmlController.js"></script>
</head>

<body ng-app="fiveer" class="m-page--fluid m--skin- m-content--skin-light2 m-header--fixed m-header--fixed-mobile m-aside-left--enabled m-aside-left--skin-dark m-aside-left--offcanvas m-footer--push m-aside--offcanvas-default">
    <div class="m-grid m-grid--hor m-grid--root m-page">

        <div class="m-grid__item m-grid__item--fluid m-wrapper">
            <div class="m-content">
                <div class="m-portlet m-portlet--space">
                    <div class="m-portlet__head">
                        <div class="m-portlet__head-caption">
                            <div class="m-portlet__head-title">
                                <div ng-view></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div ng-include="'footer.html'"></div>
    </div>

    <div id="m_scroll_top" class="m-scroll-top">
        <i class="la la-arrow-up"></i>
    </div>

    <script src="assets/vendors/base/vendors.bundle.js" type="text/javascript"></script>
    <script src="assets/demo/default/base/scripts.bundle.js" type="text/javascript"></script>
</body>

app.js

"use strict";
var app = angular.module("fiveer", ['ngRoute']);

app.config(function($routeProvider, $locationProvider) {
    alert('Hello');
    $routeProvider
        .when('/', {
            templateUrl: 'dashboard.html',
            controller: 'HtmlController'
        })

        .when('/html1', {
            templateUrl: 'src/views/html1.html',
            controller: 'HtmlController'
        })

        .when('/html2', {
            templateUrl: 'src/views/html2.html',
            controller: 'HtmlController'
        })

        otherwise({redirectTo: '/'});

        $locationProvider.hashPrefix('');
});

HtmlController.js

"use strict";
var app = angular.module("fiveer", []);

app.controller('HtmlController', ['$scope', function($scope) {
    alert('Hello');
}]);

Project Structure

https://i.sstatic.net/HsjVT.jpg

Answer №1

It seems that you are redundantly instantiating the module again in the controller. This is unnecessary and should be removed.

"use strict";
var app = angular.module("fiveer", []); //no need for this here

Your HomteCOntroller.js file should appear as follows:

HtmlController.js

app.controller('HtmlController', ['$scope', function($scope) {
    alert('Hii');
}]);

Answer №2

Erase the square brackets [] from the angular.module in the controller.

"use strict";
var app = angular.module("fiveer");

app.controller('HtmlController', ['scope', function (scope) {
    alert('Hii');
}]);

Answer №3

Make sure to check the versions of angular and angular-route.

Remember to always use camel case for your file names.

   <script src="src/controllers/htmlController.js"></script>

Always use camel case for your controller name. It may not be initializing correctly otherwise.

app.controller('htmlController', ['$scope', function($scope) {
alert('Hello');
}]);

Ensure that you have initialized ng-controller in your application.

 <head>
  <title>Apollo</title>
  <meta charset="utf-8" />
  <title>
    Testing
 </title>
<meta name="description" content="Latest updates and statistic charts">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--begin::Web font -->
<script src="public/lib/webfont.js"></script>
<script>
    WebFont.load({
        google: { "families": ["Poppins:300,400,500,600,700", "Roboto:300,400,500,600,700"] },
        active: function () {
            sessionStorage.fonts = true;
        }
    });
</script>

<link href="assets/vendors/base/vendors.bundle.css" rel="stylesheet" type="text/css" />
<link href="assets/demo/default/base/style.bundle.css" rel="stylesheet" type="text/css" />

<link href="public/css/custom.css" rel="stylesheet" type="text/css" />

<script src="public/lib/angular.min.js"></script>
<script src="public/lib/angular-route.js"></script>
<script src="app.js"></script>
<script src="src/controllers/htmlController.js"></script>
</head>

<body ng-app="fiveer" class="m-page--fluid m--skin- m-content--skin-light2 m-header-- 
 fixed m-header--fixed-mobile m-aside-left--enabled m-aside-left--skin-dark m-aside- 
 left- 
-o ffcanvas m-footer--push m-aside--offcanvas-default">
 <!-- begin:: Page -->
 <div ng-controller="htmlController" class="m-grid m-grid--hor m-grid--root m-page">
     <!-- BEGIN: Header -->

        <!-- content of html -->
        <div class="m-grid__item m-grid__item--fluid m-wrapper">
            <div class="m-content">
                <div class="m-portlet m-portlet--space">
                    <div class="m-portlet__head">
                        <div class="m-portlet__head-caption">
                            <div class="m-portlet__head-title">
                                <div ng-view></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- end of content html -->
    </div>
    <div ng-include="'footer.html'"></div>
   </div>

  <div id="m_scroll_top" class="m-scroll-top">
     <i class="la la-arrow-up"></i>
   </div>

 <script src="assets/vendors/base/vendors.bundle.js" type="text/javascript"></script>
  <script src="assets/demo/default/base/scripts.bundle.js" type="text/javascript"> 

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

Tips for handling CSS loading delays with icons in OpenLayers markers

When using openlayers (v4.6.4) with font-awesome as marker icons, the icons do not display upon first load (even after clearing cache and hard reload). Instead, I see a rectangle resembling a broken character. It is only on the second load that they appear ...

I am experiencing difficulties in creating the app while following the Ember.js 2.4 "Introduction" tutorial

Currently delving into the realm of Ember.js, I decided to start by skimming through installation tutorials using npm. Following that, I attempted a brief Getting Started tutorial provided on their website. Without much exploration, I diligently executed e ...

Challenge encountered when attempting to remove elements from an array within a for loop

There seems to be an issue with deleting elements from an array within a for loop. var div = document.querySelector('div'); var array = [ "iPad", "iPod", "iPhone" ]; for (let i = 0; i < array.length; i++) { let p = document.createElement ...

Axios is causing my Pokemon state elements to render in a jumbled order

Forgive me if this sounds like a silly question - I am currently working on a small Pokedex application using React and TypeScript. I'm facing an issue where after the initial page load, some items appear out of order after a few refreshes. This make ...

jQuery gallery remains hidden until the overlay is manually revealed

I'm experiencing an issue with a jQuery gallery placed within a full-screen absolutely positioned element that is initially hidden with display: none. When I click a button to reveal the element using jQuery .show(), only the full-screen overlay appea ...

What causes models in nested scopes to not update when the value is changed?

Snippet of code using AngularJs: <html ng-app> <body ng-controller="Controller"> <div ng-init="numbers=[11,22,33]"> <div ng-repeat="n in numbers"> <input type="text" ng-model="n"/> [{{n}}] </di ...

A step-by-step guide to adding a checkbox column dynamically within handsontable

I am currently utilizing handsontable within a jsfiddle at http://jsfiddle.net/kc11/cb920ear/1/. My task involves dynamically inserting a checkbox column before the existing data. The structure I am working with appears to be a multidimensional array, as s ...

Encountering a module injection error in AngularJS related to the ui.grid feature during my first experience with it

Trying to develop an AngularJS app, encountering the following error upon running the code: Uncaught Error: [$injector:modulerr] Failed to create module myApp: Error: [$injector:modulerr] Failed to create module ui.grid: Error: [$injector:nomod] Module &a ...

Refresh the hidden input value using an onclick event triggered by an ajax dropdown selection

I am currently working within MachForm and have incorporated a hidden field as shown below: <input type="hidden" name="element_273_price" value=""> My objective is to utilize an ajax drop-down menu that triggers an onclick event. After this event o ...

JSHint (r10): The term 'angular' is not recognized

Here is the code snippet I am working with: angular.module('test') .controller('TestMenuController', [ '$http', '$scope', '$resource', '$state', &a ...

Are you utilizing various components for laptops and mobile devices?

Framework: Meteor I am utilizing Handlebars to transmit data to the client. This layout is defined as post.html: <div class="card"> <div class="card-image waves-effect waves-block waves-light"> <img class="activator" s ...

In what ways can you shut down an electron application using JavaScript?

My Electron app is running an express server. Here is the main.js code: const electron = require("electron"), app = electron.app, BrowserWindow = electron.BrowserWindow; let mainWindow; function createWindow () { ma ...

Utilize pg-promise for inserting data with customized formatting using the placeholders :name and :

After reviewing the pg-promise documentation, I came across this code snippet: const obj = { one: 1, two: 2 }; db.query('INSERT INTO table(${this:name}) VALUES(${this:csv})', obj); //=> INSERT INTO table("one"," ...

How to Access a PHP Variable within a JavaScript Function Argument

.php <?php $timeArray = [355,400,609,1000]; $differentTimeArray = [1,45,622, 923]; ?> <script type="text/javascript"> var i=0; var eventArray = []; function generateArray(arrayName){ eventVideoArray = <?php echo json_encode(arrayName); ...

The component encounters a transformation in which prop values shift to undefined

My component seems to be encountering some instability. The value assigned to "this.state.list" from this.props is being immediately set to "undefined". I'm struggling to comprehend why this is happening. Can anyone spot the issue in the code? this.s ...

How can you handle undefined values in the query object parameter when using Mongoose's Find function?

Alright: Sound.find({ what: req.query.what, where: req.query.where, date: req.query.date, hour: req.query.hour}, function(err, varToStoreResult, count) { //perform some actions }); Let's consider a scenario where only req.query.what has a ...

Trouble with importing css in Angular webpack due to ui-bootstrap integration

Currently, I am developing an Angular application with Webpack and was looking to incorporate Bootstrap for styling purposes. To achieve this, I first installed 'ui-bootstrap' using npm install angular-ui-bootstrap --save-dev. After installation ...

Indicate that the user is unauthorized to make changes to an object belonging to a different user with the prompt “User lacks

In my project, I have a Classroom model set up like this: /** * Classroom Schema */ var ClassroomSchema = new Schema({ created: { type: Date, default: Date.now }, participants: [{ type: Schema.ObjectId, ref: & ...

Service Activation Button Click Event

When coding, I designated the path as follows: { path:'home', component: homeComponent; } In app.component.html: <button (click)="routerLink='/home'" An error occurred here Are you trying to navigate to the home page by ...

What steps can I take to ensure that WebStorm properly recognizes a package's functions?

No matter what I do, WebStorm refuses to stop throwing inspection warnings when I try to use the JOI package in my node.js project. The code runs fine and there are no runtime errors, but the warning persists. I have updated the package, explicitly install ...