Vipin Tyagi

Vipin Tyagi

  • NA
  • 2k
  • 661.7k

Difference between these two?

May 13 2016 1:11 AM
Yesterday,I posted a question on AngularJS.
Then I found the solution but still I don't know the difference b/w these 2 code snippets
 
NOT WORKING: 
<!DOCTYPE html>
<html >
<head>
<title>MyPage</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js">
</script>
</head>
<body ng-app>
{{8*9}}
<div ng-controller="mainController">
{{message}}
</div>
<script type="text/javascript">
var mainController=function($scope){
$scope.message="Hello";
};
</script>
</body>
</html>
 Note: This is working fine when I watched a Video and the guy is using Plnkr.co to run this.
 
Working: 
 
<!DOCTYPE html>
<html >
<head>
<title>MyPage</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js">
</script>
</head>
<body ng-app="myApp">
{{8*9}}
<div ng-controller="mainController">
{{message}}
</div>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller("mainController", function($scope) {
$scope.message="Hello";
});
</script>
</body>
</html>
 
Please Someone explain it!!!! 

Answers (7)