Angularjs Controller

www.ig‮fi‬tidea.com

AngularJS is a JavaScript framework used for building dynamic web applications. Controllers are one of the key components in AngularJS that are responsible for managing the application data and behavior.

A controller in AngularJS is a JavaScript function that is responsible for managing a specific part of the application. It can be thought of as the glue that binds the data and the view together. The main purpose of the controller is to set up the initial state of the $scope object, which is used to communicate between the controller and the view.

Here's an example of a simple AngularJS controller:

angular.module('myApp', [])
.controller('MyController', function($scope) {
  $scope.message = 'Hello, world!';
});

In this example, we define an AngularJS module called myApp. We then define a controller called MyController that takes a $scope object as an argument. Inside the controller function, we set a property on the $scope object called message with the value 'Hello, world!'.

Once the controller is defined, we can use it in our HTML like this:

<div ng-app="myApp" ng-controller="MyController">
  {{message}}
</div>

This will display the value of the message property from the controller on the page.

Controllers are an essential part of AngularJS, and they allow us to separate the concerns of our application into smaller, more manageable parts.