KumarM
KumarM

Reputation: 1699

AngularJS example - Uncaught Error: No module: myapp

I'm trying to run a simple hello world example and can't get it to work. What am I doing wrong here? I keep getting 'Uncaught Error: No module: myapp' error in the chrome console.

<!DOCTYPE html>
<html ng-app='myapp'>
<head>
    <title>Angular App</title>
</head>
<body>
    <div ng-controller="TextController">
        <h1>Angular App says {{greeting.message}}</h1>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"/>
    <script type="text/javascript">
        var myModule = angular.module('myapp',[]);
        myModule.controller("TextController", function($scope){
            $scope.greeting.message = "hello world!";
        });
    </script>

</body>
</html>

Here's the JSFiddle link: http://jsfiddle.net/HdR2c/1/

Upvotes: 3

Views: 7998

Answers (3)

Abhijeet
Abhijeet

Reputation: 8771

Make sure your module definition have the argument [] blocks in it, even though they are empty.

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

Upvotes: -1

Josh C.
Josh C.

Reputation: 390

You can't self close script tags first of all so you need to change your angular include to be the following:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js">
</script>

Then change your $scope.greeting.message var to something like $scope.greetingMessage. The way you are currently doing it you are looking for an attribute called "message" in a greeting object.

Upvotes: 7

juanignaciosl
juanignaciosl

Reputation: 3573

You can't self-close script tag. This is wrong:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"/>

You should close it this way:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>

Upvotes: 1

Related Questions