","url":"https://ez4code.com/snippets/angularjs-module-controller","keywords":"angularjs, module, controller","author":{"@type":"Person","name":"EZ4Code Team"},"publisher":{"@type":"Organization","name":"EZ4Code","logo":{"@type":"ImageObject","url":"https://ez4code.com/logo.png"}},"datePublished":"2024-01-01","dateModified":"2026-08-01","image":"https://ez4code.com/og-image.png"}
Define a module and a controller with scope methods.
angular.module('myApp', []);
angular.module('myApp').controller('MainController', function($scope) {
$scope.title = 'Hello AngularJS';
$scope.count = 0;
$scope.increment = function() {
$scope.count++;
};
$scope.reset = function() {
$scope.count = 0;
};
});
<!-- HTML usage -->
<body ng-app="myApp" ng-controller="MainController">
<h1>{{ title }}</h1>
<button ng-click="increment()">+1</button>
<button ng-click="reset()">Reset</button>
<p>Count: {{ count }}</p>
</body>angular.module('myApp', []) declares a module (the array lists dependencies); retrieving it without the array getter retrieves an existing module. Controllers attach state and behavior to $scope, which the template binds to via {{ }} interpolation and ng-click. ng-app bootstraps the module on the element.
Prototypal scope inheritance between parent and child controllers.
Attribute directive and element directive with isolated scope.
Factory and service singletons for shared state and logic.
Configure routes with templates, controllers, and resolve guards.
Chainable filters for formatting values in templates.
Form with required, minlength, email validation, and disabled submit.