3

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/

KumarM
  • 1,669
  • 1
  • 18
  • 26

3 Answers3

7

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.

Josh C.
  • 370
  • 2
  • 8
1

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>
juanignaciosl
  • 3,435
  • 2
  • 28
  • 28
-1

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

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

Abhijeet
  • 8,561
  • 5
  • 70
  • 76