WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AngularJS ng-controller Directive


Example

Add a controller to deal with your application variables:

<div ng-app="myApp" ng-controller="myCtrl">

Full Name: {{firstName + " " + lastName}}

</div>

<script>
var application = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});
</script>
Try it yourself »

Definition and Usage

The ng-controller order adds a controller to your application.

In the controller you can compose code, and make capacities and factors, which will be portions of an article, accessible inside the present HTML component. In AngularJS this article is known as a scope.


Syntax

<element ng-controller="expression"></element>

Supported by all HTML elements.


Parameter Values

Value Description
expression The name of the controller.