6

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

4
  • 3
    You are missing a script reference to ui-router in index.html. Commented Sep 28, 2015 at 18:38
  • You're not loading in ui router Commented Sep 28, 2015 at 18:39
  • as others have said, you don't have the script for ui.router in your HTML. Looking at your code, however, it doesn't even look like you are trying to use the library anyway. Commented Sep 28, 2015 at 18:44
  • The script for every module you include in your angular.module() app declaration needs to be included in the <head> section of your HTML, including modules that you wrote yourself. Also, you typically want to just initialize the application before applying controllers, factories, and directives. So your var app declaration would look like var app = angular.module("app", ["ui.router"]);. Then you could declare your controller with app.controller("FirstCtrl", ...);. Commented Sep 28, 2015 at 18:46

4 Answers 4

13

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)

Sign up to request clarification or add additional context in comments.

1 Comment

Down vote care to comment? Unsure what else I can add to be helpful here.
2

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>

Comments

0
<script src="angular.js"></script>

This is just the core angular library, you need to either download and host the latest angular ui router library or pull it in from a CDN

see here for more details: https://github.com/angular-ui/ui-router

Comments

0

Can be installed via nuget

PM > Install-Package Angular.UI.UI-Router

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.