Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6388a34

Browse files
committed
docs(guide/Controllers): fix headings; re-order info
1 parent 2da4917 commit 6388a34

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

docs/content/guide/controller.ngdoc

+20-23
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
In AngularJS, a Controller is defined by a JavaScript **constructor function** that is used to augment the
99
{@link scope AngularJS Scope}.
1010

11-
When a Controller is attached to the DOM via the {@link ng.directive:ngController ng-controller}
12-
directive, AngularJS will instantiate a new Controller object, using the specified Controller's
13-
**constructor function**. A new **child scope** will be created and made available as an injectable
14-
parameter to the Controller's constructor function as `$scope`.
11+
Controllers can be attached to the DOM in different ways. For each of them, AngularJS will
12+
instantiate a new Controller object, using the specified Controller's **constructor function**:
13+
14+
- the {@link ng.directive:ngController ngController} directive. A new **child scope** will be
15+
created and made available as an injectable parameter to the Controller's constructor function
16+
as `$scope`.
17+
- a route controller in a {@link ngRoute.$routeProvider $route definition}.
18+
- the controller of a {@link guide/directive regular directive}, or a
19+
{@link guide/component component directive}.
1520

1621
If the controller has been attached using the `controller as` syntax then the controller instance will
17-
be assigned to a property on the new scope.
22+
be assigned to a property on the scope.
1823

1924
Use controllers to:
2025

@@ -33,6 +38,15 @@ Do not use controllers to:
3338
services} instead.
3439
- Manage the life-cycle of other components (for example, to create service instances).
3540

41+
In general, a Controller shouldn't try to do too much. It should contain only the business logic
42+
needed for a single view.
43+
44+
The most common way to keep Controllers slim is by encapsulating work that doesn't belong to
45+
controllers into services and then using these services in Controllers via dependency injection.
46+
This is discussed in the {@link di Dependency Injection} and {@link services
47+
Services} sections of this guide.
48+
49+
3650
## Setting up the initial state of a `$scope` object
3751

3852
Typically, when you create an application you need to set up the initial state for the AngularJS
@@ -102,23 +116,6 @@ objects (or primitives) assigned to the scope become model properties. Any metho
102116
the scope are available in the template/view, and can be invoked via AngularJS expressions
103117
and `ng` event handler directives (e.g. {@link ng.directive:ngClick ngClick}).
104118

105-
## Using Controllers Correctly
106-
107-
In general, a Controller shouldn't try to do too much. It should contain only the business logic
108-
needed for a single view.
109-
110-
The most common way to keep Controllers slim is by encapsulating work that doesn't belong to
111-
controllers into services and then using these services in Controllers via dependency injection.
112-
This is discussed in the {@link di Dependency Injection} and {@link services
113-
Services} sections of this guide.
114-
115-
116-
# Associating Controllers with AngularJS Scope Objects
117-
118-
You can associate Controllers with scope objects implicitly via the {@link ng.directive:ngController ngController
119-
directive} or {@link ngRoute.$route $route service}.
120-
121-
122119
## Simple Spicy Controller Example
123120

124121
To illustrate further how Controller components work in AngularJS, let's create a little app with the
@@ -262,7 +259,7 @@ Inheritance works with methods in the same way as it does with properties. So in
262259
examples, all of the properties could be replaced with methods that return string values.
263260

264261

265-
# Testing Controllers
262+
## Testing Controllers
266263

267264
Although there are many ways to test a Controller, one of the best conventions, shown below,
268265
involves injecting the {@link ng.$rootScope $rootScope} and {@link ng.$controller $controller}:

0 commit comments

Comments
 (0)