Full Name: {{firstName + "> Full Name: {{firstName + " />
Easy Tutorial
❮ Ng Ng Open Angularjs Controllers ❯

AngularJS ng-controller Directive

AngularJS Reference Manual


AngularJS Example

Add a controller to 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>

Definition and Usage

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

Within the controller, you can write code, create functions and variables, and access them using the scope object.


Syntax

Supported by all HTML elements.


Parameter Values

Value Description
expression The name of the controller.

AngularJS Reference Manual

❮ Ng Ng Open Angularjs Controllers ❯