ngController
ng
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:
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 $route service.
<ANY ng-controller="{expression}"> ... </ANY>as class
<ANY class="ng-controller: {expression};"> ... </ANY>
Param | Type | Details |
---|---|---|
ngController | expression | Name of a globally accessible constructor function or an
expression that on the current scope evaluates to a
constructor function. The controller instance can further be published into the scope
by adding |
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. The example is included in two different declaration styles based on
your style preferences.