ngController (directive in module ng )

Improve this doc

Description

The ngController directive assigns behavior to a scope. This is a key aspect of how angular supports the principles behind the Model-View-Controller design pattern.

MVC components in angular:

Note that an alternative way to define controllers is via the <a href="api/ng.$route"><code>ng.$route</code></a> service.

Usage

as attribute
<ANY ng-controller="{expression}">
   ...
</ANY>
as class
<ANY class="ng-controller: {expression};">
   ...
</ANY>

Directive info

  • This directive creates new scope.

Parameters

Example

Here is a simple form for editing user contact information. Adding, removing, clearing, and greeting are methods declared on the controller (see source tab). These methods can easily be called from the angular markup. Notice that the scope becomes the this for the controller's instance. This allows for easy access to the view data from the controller. Also notice that any changes to the data are automatically reflected in the View without the need for a manual update.

Source







Demo