Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS example - Uncaught Error: No module: myapp

Tags:

angularjs

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/

like image 385
KumarM Avatar asked Aug 17 '26 03:08

KumarM


2 Answers

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.

like image 169
Josh C. Avatar answered Aug 19 '26 05:08

Josh C.


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>
like image 45
juanignaciosl Avatar answered Aug 19 '26 03:08

juanignaciosl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!