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

Commit 462eefc

Browse files
RichardLittpetebacondarwin
authored andcommitted
docs(ngController): add more description of controller as syntax
Using `controller as` in the template is not described well in the docs, as both `scope` injection and `this` are presented equally without too much discussion of the advantages of using either. I added a bit more discussion based on google's internal style guidelines. Closes #7591 Closes #5076 (until Angular 2.0 comes out and we refactor everything)
1 parent 3fc95e0 commit 462eefc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/ng/directive/ngController.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@
3131
* @example
3232
* Here is a simple form for editing user contact information. Adding, removing, clearing, and
3333
* greeting are methods declared on the controller (see source tab). These methods can
34-
* easily be called from the angular markup. Notice that the scope becomes the `this` for the
35-
* controller's instance. This allows for easy access to the view data from the controller. Also
36-
* notice that any changes to the data are automatically reflected in the View without the need
37-
* for a manual update. The example is shown in two different declaration styles you may use
38-
* according to preference.
34+
* easily be called from the angular markup. Any changes to the data are automatically reflected
35+
* in the View without the need for a manual update.
36+
*
37+
* Two different declaration styles are included below: one which injects `scope` into the
38+
* controller, and another which instead binds methods and properties directly onto the controller
39+
* using `this`. The first option is more common in the Angular community, and is generally used
40+
* in boilerplates and in this guide. However, there are advantages to binding properties directly
41+
* to the controller and avoiding scope. Using `controller as` makes it obvious which controller
42+
* you are accessing in the template when multiple controllers apply to an element. Since there
43+
* is always a `.` in the bindings, you don't have to worry about prototypal inheritance masking
44+
* primitives.
3945
<example>
4046
<file name="index.html">
4147
<script>

0 commit comments

Comments
 (0)