@@ -83,7 +83,7 @@ On to more complex examples!
83
83
## Factory Recipe
84
84
85
85
The Value recipe is very simple to write, but lacks some important features we often need when
86
- creating services. Let's now look at the Value recipe's more powerful sibling, the Factory.The
86
+ creating services. Let's now look at the Value recipe's more powerful sibling, the Factory. The
87
87
Factory recipe adds the following abilities:
88
88
89
89
* ability to use other services (have dependencies)
@@ -97,7 +97,7 @@ created by this recipe.
97
97
Note: All services in Angular are singletons. That means that the injector uses each recipe at most
98
98
once to create the object. The injector then caches the reference for all future needs.
99
99
100
- Since Factory is more powerful version of Value recipe, you can construct the same service with it.
100
+ Since Factory is more powerful version of the Value recipe, you can construct the same service with it.
101
101
Using our previous `clientId` Value recipe example, we can rewrite it as a Factory recipe like
102
102
this:
103
103
@@ -111,8 +111,8 @@ But given that the token is just a string literal, sticking with the Value recip
111
111
appropriate as it makes the code easier to follow.
112
112
113
113
Let's say, however, that we would also like to create a service that computes a token used for
114
- authentication against a remote API. This token will be called ' apiToken' and will be computed
115
- based on the `clientId` value and a secret stored in browser's local storage:
114
+ authentication against a remote API. This token will be called ` apiToken` and will be computed
115
+ based on the `clientId` value and a secret stored in the browser's local storage:
116
116
117
117
```javascript
118
118
myApp.factory('apiToken', ['clientId', function apiTokenFactory(clientId) {
@@ -132,7 +132,7 @@ In the code above, we see how the `apiToken` service is defined via the Factory
132
132
on `clientId` service. The factory service then uses NSA-proof encryption to produce an authentication
133
133
token.
134
134
135
- Note: It is a best practice to name the factory functions as " <serviceId>Factory"
135
+ Note: It is best practice to name the factory functions as ` <serviceId>Factory`
136
136
(e.g. apiTokenFactory). While this naming convention is not required, it helps when navigating the code base
137
137
or looking at stack traces in the debugger.
138
138
@@ -143,7 +143,7 @@ primitive, object literal, function, or even an instance of a custom type.
143
143
## Service Recipe
144
144
145
145
JavaScript developers often use custom types to write object-oriented code. Let's explore how we
146
- could launch a unicorn into space via our `unicornLauncher` service that is an instance of
146
+ could launch a unicorn into space via our `unicornLauncher` service which is an instance of a
147
147
custom type:
148
148
149
149
```javascript
@@ -187,7 +187,7 @@ myApp.service('unicornLauncher', ["apiToken", UnicornLauncher]);
187
187
Much simpler!
188
188
189
189
Note: Yes, we have called one of our service recipes 'Service'. We regret this and know that we'll
190
- be somehow punished for our mis-deed. It's like we named one of our offspring 'Children '. Boy,
190
+ be somehow punished for our mis-deed. It's like we named one of our offspring 'Child '. Boy,
191
191
that would mess with the teachers.
192
192
193
193
0 commit comments