AngularJS Question

I have started afresh learning Angular JS. Unable to figure out any mistake in the code



// Code goes here

var mainController = function($scope) {
$scope.message = "Hello Angular";
};

<!DOCTYPE html>
<html ng-app>

<head>
<script data-require="angular.js@1.5.8" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>

<body ng-controller="mainController">
<h1>{{message}}</h1>
</body>

</html>





I am very new to AngularJS. I am unable to figure out the fix to error in the following programme. Following is the link to plnkr.

HFA HFA
Answer

Here is the very basic angular app you can imagine:

<!DOCTYPE html>
<html ng-app="app">

<head>
  <script data-require="angular.js@1.5.8" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body ng-controller="MainController">
  <h1>{{message}}</h1>
</body>
</html>

and here is the js code:

angular.module('app',[])
 .controller('MainController',function($scope) {
  $scope.message = "Hello Angular";
});

you can check this plunk https://plnkr.co/edit/vNjTPZg2kt0xBdb8Xq8Z?p=preview

Comments