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

Commit 6c9131e

Browse files
cburgdorfcaitp
authored andcommitted
docs($http): remove outdated part about $http outside of $apply phase
This removes some outdated advice which no longer is true against the latest angular version. The information about unit testing with ngMocks remains, because it's always good to have information like that easily found. This little snippet is not worded perfectly, and is not a very good example unit test, so additional work is needed here. Relates to #5206 Closes #5485
1 parent 99c5027 commit 6c9131e

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/ng/http.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -223,31 +223,14 @@ function $HttpProvider() {
223223
* XMLHttpRequest will transparently follow it, meaning that the error callback will not be
224224
* called for such responses.
225225
*
226-
* # Calling $http from outside AngularJS
227-
* The `$http` service will not actually send the request until the next `$digest()` is
228-
* executed. Normally this is not an issue, since almost all the time your call to `$http` will
229-
* be from within a `$apply()` block.
230-
* If you are calling `$http` from outside Angular, then you should wrap it in a call to
231-
* `$apply` to cause a $digest to occur and also to handle errors in the block correctly.
232-
*
233-
* ```
234-
* $scope.$apply(function() {
235-
* $http(...);
236-
* });
237-
* ```
238-
*
239226
* # Writing Unit Tests that use $http
240-
* When unit testing you are mostly responsible for scheduling the `$digest` cycle. If you do
241-
* not trigger a `$digest` before calling `$httpBackend.flush()` then the request will not have
242-
* been made and `$httpBackend.expect(...)` expectations will fail. The solution is to run the
243-
* code that calls the `$http()` method inside a $apply block as explained in the previous
244-
* section.
227+
* When unit testing (using {@link api/ngMock ngMock}), it is necessary to call
228+
* {@link api/ngMock.$httpBackend#methods_flush $httpBackend.flush()} to flush each pending
229+
* request using trained responses.
245230
*
246231
* ```
247232
* $httpBackend.expectGET(...);
248-
* $scope.$apply(function() {
249-
* $http.get(...);
250-
* });
233+
* $http.get(...);
251234
* $httpBackend.flush();
252235
* ```
253236
*

0 commit comments

Comments
 (0)