0
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' is not available! 
You either misspelled the module name or forgot to load it.

I've searching a lot about my problem and can not find solution and I bet it's something silly.

My code:

myangular.js

 (function(){

    var app = angular.module('newapp', []);

    app.controller("controller", function(){
        this.creador = "daniel";
    });

});

index.html

<!DOCTYPE html>
<html ng-app="newapp">
<head>
    <title></title>
    <script src="bower_components/angular/angular.js"></script>
    <script src="js/myangular.js"></script>
</head>
<body>
    <div ng-controller="controller as cont">
        <strong>Hello World {{ cont.creador }}</strong>
    </div>

</body>
</html>
2
  • 1
    It's suspect that the console message you've logged out says myApp, not newapp. Wrong file/project/folder? Commented Aug 20, 2014 at 5:28
  • Pass a $scope to your controller function. Commented Aug 20, 2014 at 5:28

2 Answers 2

2

Don't use an anonymous jQuery function wrapper. Just use your code and it will work fine.

var app = angular.module('newapp', []);

app.controller("controller", function(){
     this.creador = "daniel";
});
Sign up to request clarification or add additional context in comments.

Comments

2

I tried your code, and I think the error message should be newApp not myApp.

You are using an IIFE(Immediately-Invoked Function Expression) but you are just defining IIFE not calling it. You are defining your newApp in this IIFE.

(function(){

    var app = angular.module('newapp', []);

    app.controller("controller", function(){
        this.creador = "daniel";
    });

})();

OR don't use IIFE say like bellow

var app = angular.module('newapp', []);

app.controller("controller", function(){
    this.creador = "daniel";
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.