Create module and add controller

Description

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><!-- w  w w .j av a2 s. com-->
<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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities