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/

0

3 Answers 3

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.

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

Comments

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>

Comments

-1

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

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

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.