Ledzz
Ledzz

Reputation: 1286

Angularjs injector error with no dependencies

Here are two files:

/login/index.php:

<!DOCTYPE html>
<html lang="ru" ng-app='login'>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/css/login.css">
</head>
<body>
<div class="border1"></div>
<div class="border2"></div>
<div class="img"></div>
<div >
    <form id="loginForm">
        <div class="logo"></div>
        <label>
            <input type="text" id="login">
            <span class="title">
                Login
            </span>
        </label>
        <label>
            <input type="password">
            <span class="title">
                Password
            </span>
        </label>
        <input type="submit" value="enter">
    </form>
</div>
<script src="/js/libs/angular.js"></script>
<script src="/app/js/_login.js"></script>
</body>
</html>

And the second one:

/app/js/_login.js:
(function() {
    'use strict';
    angular
        .module('login',[]);

});

I don't know why, but I get following error:

Uncaught Error: [$injector:modulerr] Failed to instantiate module login due to:
Error: [$injector:nomod] Module 'login' 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.

As you see, I have an empty module with no dependencies. All file path are right and flies are accessible, I can see them loaded in Dev Tools. What's the problem?

Upvotes: 0

Views: 173

Answers (1)

Simon Staton
Simon Staton

Reputation: 4505

As mentioned in your comment, you need to invoke the constructor (function(){})()

(function() {
    'use strict';
    angular
        .module('login',[]);

})();

Upvotes: 2

Related Questions