File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -186,9 +186,32 @@ function $HttpProvider() {
186
186
* XMLHttpRequest will transparently follow it, meaning that the error callback will not be
187
187
* called for such responses.
188
188
*
189
- * If your $http is scheduled from something that doesn't cause a $digest to fire then your
190
- * request won't be sent immediately. To make sure a $http request if fired immediately, wrap your
191
- * call around with an $scope.$apply(function(){ //make $http request here }
189
+ * # Calling $http from outside AngularJS
190
+ * The `$http` service will not actually send the request until the next `$digest()` is executed.
191
+ * Normally this is not an issue, since almost all the time your call to `$http` will be from within
192
+ * a `$apply()` block.
193
+ * If you are calling `$http` from outside Angular, then you should wrap it in a call to `$apply`
194
+ * to cause a $digest to occur and also to handle errors in the block correctly.
195
+ *
196
+ * ```
197
+ * $scope.$apply(function() {
198
+ * $http(...);
199
+ * });
200
+ * ```
201
+ *
202
+ * # Writing Unit Tests that use $http
203
+ * When unit testing you are mostly responsible for scheduling the `$digest` cycle. If you do not
204
+ * trigger a `$digest` before calling `$httpBackend.flush()` then the request will not have been
205
+ * made and `$httpBackend.expect(...)` expectations will fail. The solution is to run the code
206
+ * that calls the `$http()` method inside a $apply block as explained in the previous section.
207
+ *
208
+ * ```
209
+ * $httpBackend.expectGET(...);
210
+ * $scope.$apply(function() {
211
+ * $http.get(...);
212
+ * });
213
+ * $httpBackend.flush();
214
+ * ```
192
215
*
193
216
* # Shortcut methods
194
217
*
You can’t perform that action at this time.
0 commit comments