6

I'm trying to create basic angular app and it throws an error

<html>
<head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
    <script type="text/javascript">
        var angularApp = angular.module('angularApp', []);
        angularApp.controller('Ctrl', function($scope) {});
    </script>
</head>
<body>
    <div ng-app ng-controller="Ctrl"></div>
</body>
</html>

Error:

Error: [ng:areq] http://errors.angularjs.org/1.4.3/ng/areq?p0=Ctrl&p1=not%20a%20function%2C%20got%20undefined
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:6:416
    at Sb (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:22:18)
    at Qa (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:22:105)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:79:497
    at x (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:59:501)
    at S (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:60:341)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:54:384)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:53:444
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js:19:481'

What I did wrong?

1 Answer 1

6

You must give ng-app the name of your app:

<div ng-app="angularApp" ng-controller="Ctrl"></div>
Sign up to request clarification or add additional context in comments.

1 Comment

The reason this is needed is because if you don't supply a module name as the value for the ng-app attribute, Angular only bootstraps the included core ng module. Since the OP defined the Ctrl controller in their own custom module, they had to specify to load their module as well as the ng one (which gets loaded automatically regardless of whether you specify it or not).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.