Antonio Costa Antonio Costa - 4 months ago 201
Javascript Question

angular.min.js:118 Error: [ng:areq]

I'm starting learning Angular.js with this book "Angular.js OReilly", I am trying to construct the first examples that they have. I already downloaded Angular.js from the website and create my controller.js like it says, but I always get the error in the title.

This is what I did:

<html ng-app>
<head>
<script src="angular.min.js"></script>
<script src="controllers.js"></script>
</head>
<body>
<div ng-controller='HelloController'>
<p>{{greeting.text}}, World</p>
</div>
</body>
</html>

function HelloController($scope) {
console.log("a");
$scope.greeting = { text: 'Hello' };
}

Answer

Why are you using so old syntax? Try to start with new syntax you can do your above requirement like below code:

<html ng-app="myApp">
<head>
<script src="angular.min.js"></script>
<script>
var myApp = angular.module('myApp',[]);//creating app

myApp.controller('GreetingController', ['$scope', function($scope) { // creating controller
  $scope.greeting = 'Hola!';
}]);
</script>
</head>
<body>
    <div ng-controller="GreetingController">
  {{ greeting }}
</div>
</body>

First you have to make app then make a controller. try this

Comments