Anuradh S Anuradh S - 5 months ago 11
AngularJS Question

why angular gives function not undefined error (Works fine when I change the CDN version)

I'm new to MEAN stack technology and building a testing app. I'm using angulrjs as follow.

<!DOCTYPE>
<html ng-app>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<title>contact lists app</title>
</head>
<body>
<div class="container" ng-controller="AppCtrl">
<h1>Contact List app</h1>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Number</th>
</tr>
</thead>
</table>

</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

<script type="text/javascript">
function AppCtrl(){
console.log("testing");
}
</script>

</body>
</html>


while this running in the server, I looked for console in the browser.then it show following error

enter image description here

and the link description was

enter image description here

before I add this, angular works fine and didn't show any error.hope your help with this.thanx

NOTE : I tried by adding a custom js file in different folder, it also didn't work

NOTE:I'M USING GOOGLE CDN TO WORK WITH ANGULAR.IN HERE I HAVE USED LATEST VERSION, WHICH THEY ARE PROVIDING.BUT IF I USED PREVIOUS VERSION LIKE :

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script>


THEN IT WORKS FINE.

Answer

First of all you have to instantiate the module:

var app = angular.module('app', []);

Then you have to instantiate your controller:

app.controller('AppCtrl', function($scope) {

});

And in your HTML:

<html ng-app="app">

You can learn more here: