# `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:

- Model — The Model is data in scope properties; scopes are attached to the DOM.
- View — The template (HTML with data bindings) is rendered into the View.
- Controller — The `ngController` directive specifies a Controller class; the class has methods that typically express the business logic behind the application.

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

- `ngController – {expression} –`

  Name of a globally accessible constructor function or an expression that on the current scope evaluates to a constructor function.

## 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