Skip to content

Commit 08ba913

Browse files
committed
docs(tutorial/step05): fix formatting, use DI annotations in example code
1 parent 989ca61 commit 08ba913

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

docs/content/tutorial/step_05.ngdoc

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77

88
Enough of building an app with three phones in a hard-coded dataset! Let's fetch a larger dataset
9-
from our server using one of angular's built-in {@link api/ng services} called {@link
10-
api/ng.$http $http}. We will use angular's {@link guide/di dependency
9+
from our server using one of Angular's built-in {@link api/ng services} called {@link
10+
api/ng.$http $http}. We will use Angular's {@link guide/di dependency
1111
injection (DI)} to provide the service to the `PhoneListCtrl` controller.
1212

1313

@@ -42,12 +42,12 @@ Following is a sample of the file:
4242

4343
## Controller
4444

45-
We'll use angular's {@link api/ng.$http $http} service in our controller to make an HTTP
45+
We'll use Angular's {@link api/ng.$http $http} service in our controller to make an HTTP
4646
request to your web server to fetch the data in the `app/phones/phones.json` file. `$http` is just
4747
one of several built-in {@link guide/dev_guide.services angular services} that handle common operations
4848
in web apps. Angular injects these services for you where you need them.
4949

50-
Services are managed by angular's {@link guide/di DI subsystem}. Dependency injection
50+
Services are managed by Angular's {@link guide/di DI subsystem}. Dependency injection
5151
helps to make your web apps both well-structured (e.g., separate components for presentation, data,
5252
and control) and loosely coupled (dependencies between components are not resolved by the
5353
components themselves, but by the DI subsystem).
@@ -56,7 +56,7 @@ __`app/js/controllers.js:`__
5656
<pre>
5757
var phonecatApp = angular.module('phonecatApp', []);
5858

59-
phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope) {
59+
phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope, $http) {
6060
$http.get('phones/phones.json').success(function(data) {
6161
$scope.phones = data;
6262
});
@@ -92,16 +92,22 @@ dependencies.
9292
<img class="diagram" src="img/tutorial/xhr_service_final.png">
9393

9494

95-
### '$' Prefix Naming Convention
95+
### `$` Prefix Naming Convention
9696

9797
You can create your own services, and in fact we will do exactly that in step 11. As a naming
98-
convention, angular's built-in services, Scope methods and a few other angular APIs have a '$'
99-
prefix in front of the name. Don't use a '$' prefix when naming your services and models, in order
100-
to avoid any possible naming collisions.
98+
convention, angular's built-in services, Scope methods and a few other Angular APIs have a `$`
99+
prefix in front of the name.
100+
101+
The `$` prefix is there to namespace Angular-provided services.
102+
It's best to avoid naming your services and models anything that begins with a `$` to avoid
103+
104+
If you inspect a Scope, you may also notice some properties that begin with `$$`. These
105+
properties are considered private, and should not be accessed or modified.
106+
101107

102108
### A Note on Minification
103109

104-
Since angular infers the controller's dependencies from the names of arguments to the controller's
110+
Since Angular infers the controller's dependencies from the names of arguments to the controller's
105111
constructor function, if you were to {@link http://en.wikipedia.org/wiki/Minification_(programming)
106112
minify} the JavaScript code for `PhoneListCtrl` controller, all of its function arguments would be
107113
minified as well, and the dependency injector would not be able to identify services correctly.
@@ -131,6 +137,23 @@ anonymous function when registering the controller:
131137
phonecatApp.controller('PhoneListCtrl', ['$scope', '$http', function($scope, $http) {...}]);
132138

133139

140+
From this point onward, we're going to use the inline method in the tutorial. With that in mind,
141+
let's add the annotations to our `PhoneListCtrl`:
142+
143+
__`app/js/controllers.js:`__
144+
<pre>
145+
var phonecatApp = angular.module('phonecatApp', []);
146+
147+
phonecatApp.controller('PhoneListCtrl', ['$scope', '$http',
148+
function PhoneListCtrl($scope, $http) {
149+
$http.get('phones/phones.json').success(function(data) {
150+
$scope.phones = data;
151+
});
152+
153+
$scope.orderProp = 'age';
154+
}]);
155+
</pre>
156+
134157
## Test
135158

136159
__`test/unit/controllersSpec.js`:__
@@ -192,7 +215,7 @@ native APIs and the global state associated with them — both of which make tes
192215
HTTP request and tell it what to respond with. Note that the responses are not returned until we call
193216
the `$httpBackend.flush` method.
194217

195-
Now, we will make assertions to verify that the `phones` model doesn't exist on `scope` before
218+
Now we will make assertions to verify that the `phones` model doesn't exist on `scope` before
196219
the response is received:
197220

198221
<pre>
@@ -230,7 +253,7 @@ You should now see the following output in the Karma tab:
230253
displayed in json format.
231254

232255
* In the `PhoneListCtrl` controller, pre-process the http response by limiting the number of phones
233-
to the first 5 in the list. Use the following code in the $http callback:
256+
to the first 5 in the list. Use the following code in the `$http` callback:
234257

235258
$scope.phones = data.splice(0, 5);
236259

0 commit comments

Comments
 (0)