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

Commit a4072d6

Browse files
committed
feat(core): introduce $body service
This patch makes it easier to gain access to document.body via the injector.
1 parent e51024e commit a4072d6

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

angularFiles.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var angularFiles = {
1515
'src/ng/anchorScroll.js',
1616
'src/ng/animate.js',
1717
'src/ng/asyncCallback.js',
18+
'src/ng/body.js',
1819
'src/ng/browser.js',
1920
'src/ng/cacheFactory.js',
2021
'src/ng/compile.js',

src/AngularPublic.js

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
$AnimateProvider,
6060
$$CoreAnimateQueueProvider,
6161
$$CoreAnimateRunnerProvider,
62+
$BodyProvider,
6263
$BrowserProvider,
6364
$CacheFactoryProvider,
6465
$ControllerProvider,
@@ -221,6 +222,7 @@ function publishExternalAPI(angular) {
221222
$animate: $AnimateProvider,
222223
$$animateQueue: $$CoreAnimateQueueProvider,
223224
$$AnimateRunner: $$CoreAnimateRunnerProvider,
225+
$body: $BodyProvider,
224226
$browser: $BrowserProvider,
225227
$cacheFactory: $CacheFactoryProvider,
226228
$controller: $ControllerProvider,

src/ng/body.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
/**
4+
* @ngdoc service
5+
* @name $body
6+
* @requires $document
7+
*
8+
* @description
9+
* A {@link angular.element jQuery or jqLite} wrapper for the browser's `document.body` object.
10+
*/
11+
function $BodyProvider() {
12+
this.$get = ['$document', function($document) {
13+
return jqLite($document[0].body);
14+
}];
15+
}

test/ng/bodySpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
describe('$body', function() {
4+
it("should inject $document", inject(function($body, $document) {
5+
expect($body).toEqual(jqLite($document[0].body));
6+
}));
7+
});

0 commit comments

Comments
 (0)