The utilization of ui-view resulted in an error message stating "Failed to instantiate the ui.router

Recently, I've been diving into Angularjs and attempting to organize this plunker by splitting it across different files using ui-view.

Let's take a look at my app.js

'use strict';

angular.module('Main', []);

angular.module('plunker', ['angularCharts', 'Main', 'ui.router']);

angular.module('plunker').config(function ($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('app', {
            url: '',
            templateUrl: 'main.html',
        })
    $urlRouterProvider.otherwise('app')
});

Now, onto my index.html which includes ui-view

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

<head>
    <meta charset="utf-8" />
    <title>Angular-charts</title>
    <link rel="stylesheet" href="style.css" />
    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52333c35273e33207c382112637c607c60">[email protected]</a>" src="http://code.angularjs.org/1.2.2/angular.js" data-semver="1.2.2"></script>
    <script data-require="d3@*" data-semver="3.3.11" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.11/d3.js"></script>
    <script type="text/javascript" src="https://rawgit.com/chinmaymk/angular-charts/bower/dist/angular-charts.min.js"></script>
    <script src="app.js"></script>

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

</head>

<body>
    <div ui-view=""></div>
</body>

</html>

Moving on to my controller

'use strict';

angular.module('Main').controller('MainCntrl', [

function MainCtrl($scope) {
    ...
}]);

However, upon running my project, an error popped up in the console log:

Uncaught Error: [$injector:modulerr] Failed to instantiate module plunker due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router due to:
Error: [$injector:nomod] Module 'ui.router' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.2/$injector/nomod?p0=ui.router
    at https://code.angularjs.org/1.2.2/angular.js:78:12
    at https://code.angularjs.org/1.2.2/angular.js:1522:17
    at ensure (https://code.angularjs.org/1.2.2/angular.js:1447:38)
    at module (https://code.angularjs.org/1.2.2/angular.js:1520:14)
    at https://code.angularjs.org/1.2.2/angular.js:3544:22
    at Array.forEach (native)
    at forEach (https://code.angularjs.org/1.2.2/angular.js:300:11)
    at loadModules (https://code.angularjs.org/1.2.2/angular.js:3538:5)
    at https://code.angularjs.org/1.2.2/angular.js:3545:40
    at Array.forEach (native)
http://errors.angularjs.org/1.2.2/$injector/modulerr?p0=ui.router&p1=Error%…F1.2.2%2Fangular.js%3A3545%3A40%0A%20%20%20%20at%20Array.forEach%20(native)
    at https://code.angularjs.org/1.2.2/angular.js:78:12
    at https://code.angularjs.org/1.2.2/angular.js:3572:15
    at Array.forEach (native)
    at forEach (https://code.angularjs.org/1.2.2/angular.js:300:11)
    at loadModules (https://code.angularjs.org/1.2.2/angular.js:3538:5)
    at https://code.angularjs.org/1.2.2/angular.js:3545:40
    at Array.forEach (native)
    at forEach (https://code.angularjs.org/1.2.2/angular.js:300:11)
    at loadModules (https://code.angularjs.org/1.2.2/angular.js:3538:5)
    at createInjector (https://code.angularjs.org/1.2.2/angular.js:3478:11)
http://errors.angularjs.org/1.2.2/$injector/modulerr?p0=plunker&p1=Error%3A…ector%20(https%3A%2F%2Fcode.angularjs.org%2F1.2.2%2Fangular.js%3A3478%3A11)

What could be causing this issue?

Answer №1

Make sure to include ui.router in your application as a dependency, according to the documentation:

angular.module('myApp', ['angularCharts', 'Main', 'ui.router']);

Don't forget to properly configure your routes:

angular.module('myApp').config(function ($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('home', {
            // Define the URL as a directory
            url: '/',
            templateUrl: 'main.html',
        })
    // Redirect to the '/home' route.
    $urlRouterProvider.otherwise('/home')
});

Ensure that you have included angular-ui-router.js in your index page:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.17/angular-ui-router.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

Toggle the visibility of a div based on whether or not certain fields have been filled

Having a form with a repeater field... <table class="dokan-table"> <tfoot> <tr> <th colspan="3"> <?php $file = [ 'file' => ...

Updating two separate <DIV> elements with a single AJAX request

Can two different targeted DIVs be updated simultaneously using a single ajax call? Consider the index.html code snippet below: <script> xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.rea ...

The performance of aframe is being affected by the use of bounding boxes for collision

Hey there! I recently created a component to handle collision detection for primitive and non-primitive shapes. While using the bounding box collision feature provided in three.js, everything was working smoothly. However, when applying it to custom object ...

Having trouble accessing the height of a div within an Iframe

Here is the issue I am facing: I need my iFrame to adjust its size based on a div within it, but every attempt to retrieve the size of this div results in 0. var childiFrame = document.getElementById("myDiv"); console.log(childiFra ...

In the setup function, the composition API calculates the return value of the computed property before it is

I am currently working on editing a post using the state manager Vuex in Vue3 with Composition API. Below is the code I have implemented: <template> <div class="container py-5"> <h3 class="mb-5 border-top-0 border-start- ...

Is it more effective to import an entire library or specific component when incorporating it into Create-React-App?

I have a question about optimizing performance. I understand that every library has its own export method, but for instance, on react-bootstrap's official documentation, it suggests: It is recommended to import individual components like: react-boo ...

AngularJS and Karma: Revoking ng-dirty status using setPristine

I'm currently facing an issue in one of my unit tests where I am testing the removal of ng-dirty when using setPristine on an input element. Even after calling setPristine, the ng-dirty is not being removed. My suspicion is that I may be incorrectly ...

Shuffle the contents of various div elements, conceal one, reveal another

I am currently working with a menu that uses the loadContent function to load pages into the #main div. This allows me to change the content of the page while keeping the menu intact. <ul> <li class="page1" onclick="loadContent('page1.php ...

click event on ion card

Attempting to handle a click event within an ion-card using Ionic 5.0.2 version has presented some challenges. Despite my efforts, I have not been successful in handling the event with the expected function. Here is a snippet of my code: Dynamic card list ...

The use of callbacks in Model.findById() is now deprecated due to a MongooseError

Hello there! I've run into an issue and could use some assistance, thank you in advance! Running MONGOOSE VERSION: "mongoose": "^7.0.3" Error Message: MongooseError: Model.findById() no longer accepts a callback at Function.findB ...

Generating a bullet list from an array of objects

Looking to create an unordered list with vanilla JS, using an array of objects to populate the list. Struggling a bit on how to accomplish this. Here is my current code: let myObj = [ {name: "Harry Potter", author: "JK Rowling"}, {name: "Hunger Gam ...

Keep an eye on the syncing progress of pouchdb replication

What is the best way to alert the user if there is a loss of Internet connection or if the server goes offline, causing live sync to stop? var localdb = new PouchDB('localdb'); var remotedb = new PouchDB('http://localhost:5984/xyz&a ...

I am interested in utilizing node.js to input data into a mongodb Database

Currently, I am working on writing data to a JSON file and retrieving it back to an HTML page for display. Now, I want to achieve the same functionality with a MongoDB database. I have made some attempts, but unfortunately, it is not functioning as expecte ...

Troubleshooting problem with updating a record in the MongoDB using Node.js and

Currently, I am developing a REST API using Node, Express, and MongoDB. I have successfully implemented fetch, create, and delete functions but facing issues with the update function. Every time I attempt to test it using Postman, the code hangs, the serve ...

Unable to modify $scope value within the directive

This special function triggers once ng-repeat is done iterating through the list using scope.$last: simpleSearchApp.directive('afterResults', function($document) { return function(scope, element, attrs) { if (scope.$last){ scope.windowHe ...

Is it possible to access static files outside the root directory using express.js?

I currently have an Express app set up to act as a proxy for certain requests originating from an Angular app. The Angular app is already built with a configuration that I do not want to change. My goal is to organize my Angular and Express apps in separa ...

The URL is displaying the MVC controller's name twice

Currently, I am developing a project using .NET MVC and AngularJS technologies. Within my HomeController file: public ActionResult Index() { return View(); } In the Angular controller, there is a service designed to retrieve all item ...

Unshifting values in a JavaScript array only if they exist in another array

I have two arrays of objects - one containing selected data and the other containing general data that needs to be displayed General data for display const arr = [ { id: "1", name: "Skoda - Auto" }, { id: "2" ...

What could be causing my post request to function properly in POSTMAN but not in my React application?

Here are my POSTMAN headers along with the settings I used to send my POST. It only started working when I switched the Content-Type to application/json. https://i.stack.imgur.com/Xz2As.png https://i.stack.imgur.com/aJtbD.png This pertains to the server ...

Error encountered: DataTable - Unable to retrieve the 'length' property of a null value

I am currently using a datatable in my project: function drawRadnici() { $('#tableradnici').dataTable({ "ajax": { "url": 'track_radnici.php', "type": 'POST' ...