AngularJS ng-controllerDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Add a controller to the application variable:

<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 Yourself »

Definition and Usage

ng-controllerThe directive is used to add a controller to your application.

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


Syntax

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

Supported by all HTML elements.


Parameter Value

Value Description
expression Controller name.

AngularJS 参考手册AngularJS Reference Manual

Other extensions