AngularJS Tutorial - Add controller to module








The following code shows how to Add controller to module.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from  w  w  w . java 2  s  .  c  o  m-->
<body ng-app="myApp">
  <div ng-controller="myController">
  Hello, {{name}}!
</div>
<script type='text/javascript'>
(function () {
"use strict";
    angular.module('myApp',[]).controller('myController', function($scope) {
        $scope.name = 'World';
        // Do things
    });

}());


</script>
</body>
</html>

The code above is rendered as follows: