AngularJS ng-controller Instruction
AngularJS Examples
Add a controller for the application variables:
<
div
ng-app=
"myApp"
ng-controller=
"myCtrl"
Full Name:
{{firstName + " " + lastName}}
<
/div
<
script
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
<
/script
Try it »
Definition and Usage
ng-controller The directive is used to add a controller to your application.
In the controller, you can write code, create functions and variables, and access them using the scope object.
Syntax
<
element
ng-controller=
"expression"
<
/element
All HTML elements are supported.
Parameter value
| Value | Description |
|---|---|
| expression | The name of the controller. |
AngularJS Reference Manual