English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS ng-controller directive

AngularJS Reference Manual

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<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>
<p>This example demonstrates how to define a controller and use the scope.</p>/p>
</body>
</html>
Test and See ‹/›

Definition and Usage

ng-controller Directives are used to add controllers to your application.

In the controller, you can write code, create functions and variables, and use the scope object to access.

Syntax

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

All HTML elements support.

Parameter Value

ValueDescription
expressionController Name.

AngularJS Reference Manual