Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module 'ui.router' is not available

Tags:

angularjs

I`m new in AngularJS

I`m getting this error:

Uncaught Error: [$injector:modulerr] Failed to instantiate module app 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.

this is index.html file:

<!doctype html>
<html ng-app="app">
    <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <meta charset="utf-8">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Untitled</title>
        <link rel="stylesheet" href="css/style.css">
        <link rel="author" href="humans.txt">



    </head>
    <body ng-controller="FirstCtrl">

    <input type="text" ng-model="first.greeting"/>
    <div ng-class="first.greeting">{{first.greeting}}</div>



    <script src="angular.js"></script>
    <script src="app/app.js"></script>
    <script src="js/main.js"></script>
    </body>
</html>

and this is app.js file:

var app = angular.module("app", ["ui.router"]).controller("FirstCtrl", function FirstCtrl(){
            var first = this;
            first.greeting = "First";
        });

Please help me to solve this issue

like image 897
Nuriddin Zuhirxojaev Avatar asked Sep 28 '15 18:09

Nuriddin Zuhirxojaev


2 Answers

You're not loading in the ui-router script, I don't know if you have it locally or using a cdn, you just need to add it in your index.html there

for example, by adding-

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>

in your index.html (this is a cdn link)

like image 169
ajmajmajma Avatar answered Nov 15 '22 10:11

ajmajmajma


Fixed by following steps:

Installed angular-ui-router via npm

npm install [email protected] --save

Then load the script in index.html (angular 1.5.0)

<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
like image 39
Nitin Avatar answered Nov 15 '22 09:11

Nitin