AngularJS Tutorial - Create module and add controller








The following code shows how to Create module and add controller.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from   www  . j  a  v  a 2  s .  c o m-->
<body>
  <div ng-app="myApp">
    <div ng-controller="firstController">
         {{ text }}
    </div>
</div>
<script type='text/javascript'>

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

myApp.controller('firstController', ['$scope', function ($scope) {    
    $scope.text = 'Hi';    
}]);
</script>
</body>
</html>

The code above is rendered as follows: