@@ -13,7 +13,7 @@ In this step, you will improve the way our app fetches data.
13
13
14
14
The last improvement we will make to our app is to define a custom service that represents a {@link
15
15
http://en.wikipedia.org/wiki/Representational_State_Transfer RESTful} client. Using this client we
16
- can make xhr requests for data in an easier way, without having to deal with the lower-level {@link
16
+ can make XHR requests for data in an easier way, without having to deal with the lower-level {@link
17
17
api/ng.$http $http} API, HTTP methods and URLs.
18
18
19
19
The most important changes are listed below. You can see the full diff on {@link
@@ -57,13 +57,22 @@ The {@link api/ngResource.$resource `$resource`} service makes it easy to create
57
57
lines of code. This client can then be used in our application, instead of the lower-level {@link
58
58
api/ng.$http $http} service.
59
59
60
+ __`app/js/app.js`.__
61
+ <pre>
62
+ ...
63
+ angular.module('phonecat', ['phonecatFilters', 'phonecatServices']).
64
+ ...
65
+ </pre>
66
+
67
+ We need to add 'phonecatServices' to 'phonecat' application's requires array.
68
+
60
69
61
70
## Controller
62
71
63
72
We simplified our sub-controllers (`PhoneListCtrl` and `PhoneDetailCtrl`) by factoring out the
64
73
lower-level {@link api/ng.$http $http} service, replacing it with a new service called
65
74
`Phone`. Angular's {@link api/ngResource.$resource `$resource`} service is easier to
66
- use than `$http for interacting with data sources exposed as RESTful resources. It is also easier
75
+ use than `$http` for interacting with data sources exposed as RESTful resources. It is also easier
67
76
now to understand what the code in our controllers is doing.
68
77
69
78
__`app/js/controllers.js`.__
@@ -107,8 +116,8 @@ This is a simple statement that we want to query for all phones.
107
116
An important thing to notice in the code above is that we don't pass any callback functions when
108
117
invoking methods of our Phone service. Although it looks as if the result were returned
109
118
synchronously, that is not the case at all. What is returned synchronously is a "future" — an
110
- object, which will be filled with data when the xhr response returns. Because of the data-binding
111
- in angular , we can use this future and bind it to our template. Then, when the data arrives, the
119
+ object, which will be filled with data when the XHR response returns. Because of the data-binding
120
+ in Angular , we can use this future and bind it to our template. Then, when the data arrives, the
112
121
view will automatically update.
113
122
114
123
Sometimes, relying on the future object and data-binding alone is not sufficient to do everything
0 commit comments