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

Commit 3ff0df4

Browse files
squash-me! feat(Module): add info() method
The new `info()` method lets developers store arbitrary information about their module for consumption later.
1 parent 213aa0d commit 3ff0df4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/loader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,20 @@ function setupModuleLoader(window) {
127127
* or `this` if called as a setter.
128128
*
129129
* @description
130-
* Additional info about this module
130+
* Read and write custom information about this module.
131131
* For example you could put the version of the module in here.
132132
*
133133
* ```js
134134
* angular.module('myModule', []).info({ version: '1.0.0' });
135135
* ```
136136
*
137-
* You can retrieve this information during runtime via the
137+
* The version could then be read back out by accessing the module elsewhere:
138+
*
139+
* ```
140+
* var version = angular.module('myModule').info().version;
141+
* ```
142+
*
143+
* You can also retrieve this information during runtime via the
138144
* {@link $injector#modules `$injector.modules`} property:
139145
*
140146
* ```js

test/loaderSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ describe('module loader', function() {
179179
theModule.info('some text');
180180
}).toThrowMinErr('ng', 'aobj');
181181
});
182+
183+
it('should completely replace the previous info object', function() {
184+
theModule.info({ value: 'X' });
185+
theModule.info({ newValue: 'Y' });
186+
expect(theModule.info()).toEqual({ newValue: 'Y' });
187+
});
182188
});
183189
});
184190
});

0 commit comments

Comments
 (0)