@angular-wave/angular.ts 0.0.63 → 0.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +6 -2
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +1 -1
- package/src/angular.spec.js +13 -18
- package/src/animations/module.js +2 -2
- package/src/binding.spec.js +6 -3
- package/src/core/animate/animate.spec.js +1 -3
- package/src/core/cache/cache-factory.spec.js +2 -2
- package/src/core/compile/compile.spec.js +64 -57
- package/src/core/controller/controller.spec.js +2 -2
- package/src/core/cookie-reader.spec.js +2 -2
- package/src/core/filter/filter.spec.js +4 -4
- package/src/core/interpolate/interpolate.spec.js +2 -2
- package/src/core/interval/interval.spec.js +10 -7
- package/src/core/location/location.spec.js +2 -2
- package/src/core/ng-module.js +167 -0
- package/src/core/on.spec.js +2 -2
- package/src/core/parser/lexer.spec.js +11 -8
- package/src/core/parser/parse.spec.js +11 -8
- package/src/core/prop.spec.js +47 -35
- package/src/core/q/q.spec.js +6 -6
- package/src/core/root-element.spec.js +0 -2
- package/src/core/sce/sce.spec.js +7 -6
- package/src/core/scope/scope.spec.js +11 -8
- package/src/core/timeout/timeout.spec.js +10 -7
- package/src/directive/attrs/attrs.spec.js +4 -3
- package/src/directive/attrs/boolean.spec.js +2 -2
- package/src/directive/attrs/element-style.spec.js +4 -3
- package/src/directive/attrs/src.spec.js +7 -5
- package/src/directive/bind/bind.spec.js +10 -7
- package/src/directive/bind/bing-html.spec.js +2 -2
- package/src/directive/change/change.spec.js +2 -2
- package/src/directive/class/class.spec.js +2 -2
- package/src/directive/cloak/cloak.spec.js +2 -2
- package/src/directive/controller/controller.spec.js +2 -3
- package/src/directive/events/click.spec.js +2 -2
- package/src/directive/events/event.spec.js +16 -13
- package/src/directive/form/form.spec.js +11 -9
- package/src/directive/if/if.spec.js +2 -3
- package/src/directive/include/include.spec.js +11 -10
- package/src/directive/init/init.spec.js +2 -3
- package/src/directive/input/input.spec.js +10 -7
- package/src/directive/list/list.spec.js +2 -2
- package/src/directive/model/model.spec.js +11 -11
- package/src/directive/model-options/model-options.spec.js +11 -9
- package/src/directive/non-bindable/non-bindable.spec.js +10 -7
- package/src/directive/options/options.spec.js +10 -7
- package/src/directive/ref/href.spec.js +11 -8
- package/src/directive/ref/ref.spec.js +10 -7
- package/src/directive/repeat/repeat.spec.js +11 -10
- package/src/directive/script/script.spec.js +4 -3
- package/src/directive/select/select.spec.js +10 -7
- package/src/directive/show-hide/show-hide.spec.js +4 -3
- package/src/directive/style/style.spec.js +9 -6
- package/src/directive/switch/switch.spec.js +2 -2
- package/src/directive/validators/validators.spec.js +12 -9
- package/src/exts/aria/aria.js +2 -2
- package/src/exts/aria/aria.spec.js +2 -2
- package/src/exts/messages/messages.js +2 -2
- package/src/exts/messages/messages.spec.js +2 -2
- package/src/filters/filter.spec.js +4 -3
- package/src/filters/filters.spec.js +4 -3
- package/src/filters/limit-to.spec.js +4 -3
- package/src/filters/order-by.spec.js +7 -5
- package/src/index.js +2 -8
- package/src/injector.spec.js +26 -29
- package/src/loader.js +106 -538
- package/src/loader.md +142 -0
- package/src/loader.spec.js +5 -9
- package/src/public.js +113 -107
- package/src/public.spec.js +2 -4
- package/src/router/directives/state-directives.spec.js +0 -3
- package/src/router/directives/view-directive.spec.js +0 -6
- package/src/router/index.js +2 -2
- package/src/router/services.spec.js +0 -2
- package/src/router/state/state.spec.js +2 -4
- package/src/router/state-filter.spec.js +0 -2
- package/src/router/template-factory.spec.js +0 -2
- package/src/router/url/url-service.spec.js +0 -2
- package/src/router/view/view.spec.js +1 -2
- package/src/router/view-hook.spec.js +0 -2
- package/src/router/view-scroll.spec.js +0 -3
- package/src/services/http/http.spec.js +2 -2
- package/src/services/http/template-request.spec.js +3 -3
- package/src/services/http-backend/http-backend.spec.js +3 -2
- package/src/shared/jqlite/jqlite.spec.js +3 -4
- package/src/shared/test-utils.js +1 -1
- package/types/animations/module.d.ts +1 -1
- package/types/core/ng-module.d.ts +57 -0
- package/types/exts/aria/aria.d.ts +1 -1
- package/types/exts/messages/messages.d.ts +1 -1
- package/types/index.d.ts +0 -3
- package/types/loader.d.ts +53 -179
- package/types/public.d.ts +6 -1
- package/types/router/index.d.ts +1 -1
- package/types/shared/test-utils.d.ts +3 -2
package/src/loader.js
CHANGED
|
@@ -2,23 +2,22 @@ import {
|
|
|
2
2
|
minErr,
|
|
3
3
|
forEach,
|
|
4
4
|
getNgAttribute,
|
|
5
|
-
isFunction,
|
|
6
|
-
isObject,
|
|
7
5
|
ngAttrPrefixes,
|
|
8
|
-
isDefined,
|
|
9
6
|
assertNotHasOwnProperty,
|
|
10
7
|
errorHandlingConfig,
|
|
11
8
|
} from "./shared/utils";
|
|
12
9
|
import { JQLite } from "./shared/jqlite/jqlite";
|
|
13
10
|
import { createInjector } from "./injector";
|
|
14
11
|
import { CACHE } from "./core/cache/cache";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
export const VERSION = "[VI]{version}[/VI]";
|
|
12
|
+
import { publishExternalAPI } from "./public";
|
|
13
|
+
import { NgModule } from "./core/ng-module";
|
|
14
|
+
import { VERSION } from "./public";
|
|
20
15
|
|
|
21
16
|
const ngMinErr = minErr("ng");
|
|
17
|
+
const $injectorMinErr = minErr("$injector");
|
|
18
|
+
|
|
19
|
+
/** @type {Object.<string, import('./types').Module>} */
|
|
20
|
+
const modules = {};
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* Configuration option for AngularTS bootstrap process.
|
|
@@ -27,9 +26,6 @@ const ngMinErr = minErr("ng");
|
|
|
27
26
|
* @property {boolean} [strictDi] - Disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. Defaults to `false`.
|
|
28
27
|
*/
|
|
29
28
|
|
|
30
|
-
/**
|
|
31
|
-
* @class
|
|
32
|
-
*/
|
|
33
29
|
export class Angular {
|
|
34
30
|
constructor() {
|
|
35
31
|
CACHE.clear(); // a ensure new instance of angular gets a clean cache
|
|
@@ -48,6 +44,7 @@ export class Angular {
|
|
|
48
44
|
|
|
49
45
|
/** @type {Function} */
|
|
50
46
|
this.doBootstrap;
|
|
47
|
+
publishExternalAPI(this);
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
/**
|
|
@@ -66,18 +63,11 @@ export class Angular {
|
|
|
66
63
|
/**
|
|
67
64
|
* Use this function to manually start up AngularJS application.
|
|
68
65
|
*
|
|
69
|
-
* For more information, see the {@link guide/bootstrap Bootstrap guide}.
|
|
70
|
-
*
|
|
71
66
|
* AngularJS will detect if it has been loaded into the browser more than once and only allow the
|
|
72
67
|
* first loaded script to be bootstrapped and will report a warning to the browser console for
|
|
73
68
|
* each of the subsequent scripts. This prevents strange results in applications, where otherwise
|
|
74
69
|
* multiple instances of AngularJS try to work on the DOM.
|
|
75
|
-
*
|
|
76
|
-
* <div class="alert alert-warning">
|
|
77
|
-
* **Note:** Protractor based end-to-end tests cannot use this function to bootstrap manually.
|
|
78
|
-
* They must use {@link ng.directive:ngApp ngApp}.
|
|
79
|
-
* </div>
|
|
80
|
-
*
|
|
70
|
+
* *
|
|
81
71
|
* <div class="alert alert-warning">
|
|
82
72
|
* **Note:** Do not bootstrap the app on an element with a directive that uses {@link ng.$compile#transclusion transclusion},
|
|
83
73
|
* such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and {@link ngRoute.ngView `ngView`}.
|
|
@@ -199,529 +189,107 @@ export class Angular {
|
|
|
199
189
|
}
|
|
200
190
|
|
|
201
191
|
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
* Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive
|
|
235
|
-
* designates the **root element** of the application and is typically placed near the root element
|
|
236
|
-
* of the page - e.g. on the `<body>` or `<html>` tags.
|
|
237
|
-
*
|
|
238
|
-
* There are a few things to keep in mind when using `ngApp`:
|
|
239
|
-
* - only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
|
|
240
|
-
* found in the document will be used to define the root element to auto-bootstrap as an
|
|
241
|
-
* application. To run multiple applications in an HTML document you must manually bootstrap them using
|
|
242
|
-
* {@link angular.bootstrap} instead.
|
|
243
|
-
* - AngularJS applications cannot be nested within each other.
|
|
244
|
-
* - Do not use a directive that uses {@link ng.$compile#transclusion transclusion} on the same element as `ngApp`.
|
|
245
|
-
* This includes directives such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and
|
|
246
|
-
* {@link ngRoute.ngView `ngView`}.
|
|
247
|
-
* Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
|
|
248
|
-
* causing animations to stop working and making the injector inaccessible from outside the app.
|
|
249
|
-
*
|
|
250
|
-
* You can specify an **AngularJS module** to be used as the root module for the application. This
|
|
251
|
-
* module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It
|
|
252
|
-
* should contain the application code needed or have dependencies on other modules that will
|
|
253
|
-
* contain the code. See {@link angular.module} for more information.
|
|
254
|
-
*
|
|
255
|
-
* In the example below if the `ngApp` directive were not placed on the `html` element then the
|
|
256
|
-
* document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}`
|
|
257
|
-
* would not be resolved to `3`.
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
*
|
|
261
|
-
* ### Simple Usage
|
|
262
|
-
*
|
|
263
|
-
* `ngApp` is the easiest, and most common way to bootstrap an application.
|
|
264
|
-
*
|
|
265
|
-
<example module="ngAppDemo" name="ng-app">
|
|
266
|
-
<file name="index.html">
|
|
267
|
-
<div ng-controller="ngAppDemoController">
|
|
268
|
-
I can add: {{a}} + {{b}} = {{ a+b }}
|
|
269
|
-
</div>
|
|
270
|
-
</file>
|
|
271
|
-
<file name="script.js">
|
|
272
|
-
angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
|
|
273
|
-
$scope.a = 1;
|
|
274
|
-
$scope.b = 2;
|
|
275
|
-
});
|
|
276
|
-
</file>
|
|
277
|
-
</example>
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
*
|
|
281
|
-
* ### With `ngStrictDi`
|
|
282
|
-
*
|
|
283
|
-
* Using `ngStrictDi`, you would see something like this:
|
|
284
|
-
*
|
|
285
|
-
<example ng-app-included="true" name="strict-di">
|
|
286
|
-
<file name="index.html">
|
|
287
|
-
<div ng-app="ngAppStrictDemo" ng-strict-di>
|
|
288
|
-
<div ng-controller="GoodController1">
|
|
289
|
-
I can add: {{a}} + {{b}} = {{ a+b }}
|
|
290
|
-
|
|
291
|
-
<p>This renders because the controller does not fail to
|
|
292
|
-
instantiate, by using explicit annotation style (see
|
|
293
|
-
script.js for details)
|
|
294
|
-
</p>
|
|
295
|
-
</div>
|
|
296
|
-
|
|
297
|
-
<div ng-controller="GoodController2">
|
|
298
|
-
Name: <input ng-model="name"><br />
|
|
299
|
-
Hello, {{name}}!
|
|
300
|
-
|
|
301
|
-
<p>This renders because the controller does not fail to
|
|
302
|
-
instantiate, by using explicit annotation style
|
|
303
|
-
(see script.js for details)
|
|
304
|
-
</p>
|
|
305
|
-
</div>
|
|
306
|
-
|
|
307
|
-
<div ng-controller="BadController">
|
|
308
|
-
I can add: {{a}} + {{b}} = {{ a+b }}
|
|
309
|
-
|
|
310
|
-
<p>The controller could not be instantiated, due to relying
|
|
311
|
-
on automatic function annotations (which are disabled in
|
|
312
|
-
strict mode). As such, the content of this section is not
|
|
313
|
-
interpolated, and there should be an error in your web console.
|
|
314
|
-
</p>
|
|
315
|
-
</div>
|
|
316
|
-
</div>
|
|
317
|
-
</file>
|
|
318
|
-
<file name="script.js">
|
|
319
|
-
angular.module('ngAppStrictDemo', [])
|
|
320
|
-
// BadController will fail to instantiate, due to relying on automatic function annotation,
|
|
321
|
-
// rather than an explicit annotation
|
|
322
|
-
.controller('BadController', function($scope) {
|
|
323
|
-
$scope.a = 1;
|
|
324
|
-
$scope.b = 2;
|
|
325
|
-
})
|
|
326
|
-
// Unlike BadController, GoodController1 and GoodController2 will not fail to be instantiated,
|
|
327
|
-
// due to using explicit annotations using the array style and $inject property, respectively.
|
|
328
|
-
.controller('GoodController1', ['$scope', function($scope) {
|
|
329
|
-
$scope.a = 1;
|
|
330
|
-
$scope.b = 2;
|
|
331
|
-
}])
|
|
332
|
-
.controller('GoodController2', GoodController2);
|
|
333
|
-
function GoodController2($scope) {
|
|
334
|
-
$scope.name = 'World';
|
|
335
|
-
}
|
|
336
|
-
GoodController2.$inject = ['$scope'];
|
|
337
|
-
</file>
|
|
338
|
-
<file name="style.css">
|
|
339
|
-
div[ng-controller] {
|
|
340
|
-
margin-bottom: 1em;
|
|
341
|
-
-webkit-border-radius: 4px;
|
|
342
|
-
border-radius: 4px;
|
|
343
|
-
border: 1px solid;
|
|
344
|
-
padding: .5em;
|
|
345
|
-
}
|
|
346
|
-
div[ng-controller^=Good] {
|
|
347
|
-
border-color: #d6e9c6;
|
|
348
|
-
background-color: #dff0d8;
|
|
349
|
-
color: #3c763d;
|
|
350
|
-
}
|
|
351
|
-
div[ng-controller^=Bad] {
|
|
352
|
-
border-color: #ebccd1;
|
|
353
|
-
background-color: #f2dede;
|
|
354
|
-
color: #a94442;
|
|
355
|
-
margin-bottom: 0;
|
|
356
|
-
}
|
|
357
|
-
</file>
|
|
358
|
-
</example>
|
|
359
|
-
*/
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* @param {Element|Document} element
|
|
363
|
-
*/
|
|
364
|
-
export function angularInit(element) {
|
|
365
|
-
let appElement;
|
|
366
|
-
let module;
|
|
367
|
-
const config = {};
|
|
368
|
-
|
|
369
|
-
// The element `element` has priority over any other element.
|
|
370
|
-
ngAttrPrefixes.forEach((prefix) => {
|
|
371
|
-
const name = `${prefix}app`;
|
|
372
|
-
|
|
373
|
-
if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
|
|
374
|
-
appElement = element;
|
|
375
|
-
module = element.getAttribute(name);
|
|
192
|
+
* @param {Element|Document} element
|
|
193
|
+
*/
|
|
194
|
+
init(element) {
|
|
195
|
+
let appElement;
|
|
196
|
+
let module;
|
|
197
|
+
const config = {};
|
|
198
|
+
// The element `element` has priority over any other element.
|
|
199
|
+
ngAttrPrefixes.forEach((prefix) => {
|
|
200
|
+
const name = `${prefix}app`;
|
|
201
|
+
if (
|
|
202
|
+
/** @type {Element} */ (element).hasAttribute &&
|
|
203
|
+
/** @type {Element} */ (element).hasAttribute(name)
|
|
204
|
+
) {
|
|
205
|
+
appElement = element;
|
|
206
|
+
module = /** @type {Element} */ (element).getAttribute(name);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
ngAttrPrefixes.forEach((prefix) => {
|
|
210
|
+
const name = `${prefix}app`;
|
|
211
|
+
let candidate;
|
|
212
|
+
|
|
213
|
+
if (
|
|
214
|
+
!appElement &&
|
|
215
|
+
(candidate = element.querySelector(`[${name.replace(":", "\\:")}]`))
|
|
216
|
+
) {
|
|
217
|
+
appElement = candidate;
|
|
218
|
+
module = candidate.getAttribute(name);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
if (appElement) {
|
|
222
|
+
config.strictDi = getNgAttribute(appElement, "strict-di") !== null;
|
|
223
|
+
this.bootstrap(appElement, module ? [module] : [], config);
|
|
376
224
|
}
|
|
377
|
-
}
|
|
378
|
-
ngAttrPrefixes.forEach((prefix) => {
|
|
379
|
-
const name = `${prefix}app`;
|
|
380
|
-
let candidate;
|
|
225
|
+
}
|
|
381
226
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
* The `angular.module` is a global place for creating, registering and retrieving AngularJS
|
|
230
|
+
* modules.
|
|
231
|
+
* All modules (AngularJS core or 3rd party) that should be available to an application must be
|
|
232
|
+
* registered using this mechanism.
|
|
233
|
+
*
|
|
234
|
+
* Passing one argument retrieves an existing {@link import('./types').Module},
|
|
235
|
+
* whereas passing more than one argument creates a new {@link import('./types').Module}
|
|
236
|
+
*
|
|
237
|
+
*
|
|
238
|
+
* # Module
|
|
239
|
+
*
|
|
240
|
+
* A module is a collection of services, directives, controllers, filters, and configuration information.
|
|
241
|
+
* `angular.module` is used to configure the {@link auto.$injector $injector}.
|
|
242
|
+
*
|
|
243
|
+
* ```js
|
|
244
|
+
* // Create a new module
|
|
245
|
+
* let myModule = angular.module('myModule', []);
|
|
246
|
+
*
|
|
247
|
+
* // register a new service
|
|
248
|
+
* myModule.value('appName', 'MyCoolApp');
|
|
249
|
+
*
|
|
250
|
+
* // configure existing services inside initialization blocks.
|
|
251
|
+
* myModule.config(['$locationProvider', function($locationProvider) {
|
|
252
|
+
* // Configure existing providers
|
|
253
|
+
* $locationProvider.hashPrefix('!');
|
|
254
|
+
* }]);
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* Then you can create an injector and load your modules like this:
|
|
258
|
+
*
|
|
259
|
+
* ```js
|
|
260
|
+
* let injector = angular.injector(['ng', 'myModule'])
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* However it's more likely that you'll just use
|
|
264
|
+
* {@link ng.directive:ngApp ngApp} or
|
|
265
|
+
* {@link angular.bootstrap} to simplify this process for you.
|
|
266
|
+
*
|
|
267
|
+
* @param {!string} name The name of the module to create or retrieve.
|
|
268
|
+
* @param {!Array.<string>=} requires If specified then new module is being created. If
|
|
269
|
+
* unspecified then the module is being retrieved for further configuration.
|
|
270
|
+
* @param {Function=} configFn Optional configuration function for the module. Same as
|
|
271
|
+
* {@link import('./types').Module#config Module#config()}.
|
|
272
|
+
* @returns {NgModule} A newly registered module.
|
|
273
|
+
*/
|
|
274
|
+
module(name, requires, configFn) {
|
|
275
|
+
assertNotHasOwnProperty(name, "module");
|
|
276
|
+
if (requires && Object.prototype.hasOwnProperty.call(modules, name)) {
|
|
277
|
+
modules[name] = null;
|
|
388
278
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
279
|
+
return ensure(modules, name, () => {
|
|
280
|
+
if (!requires) {
|
|
281
|
+
throw $injectorMinErr(
|
|
282
|
+
"nomod",
|
|
283
|
+
"Module '{0}' is not available. Possibly misspelled or not loaded",
|
|
284
|
+
name,
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const moduleInstance = new NgModule(name, requires, configFn);
|
|
288
|
+
return moduleInstance;
|
|
289
|
+
});
|
|
393
290
|
}
|
|
394
291
|
}
|
|
395
292
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* @name import('./types').Module
|
|
399
|
-
* @module ng
|
|
400
|
-
* @description
|
|
401
|
-
*
|
|
402
|
-
* Interface for configuring AngularJS {@link angular.module modules}.
|
|
403
|
-
*/
|
|
404
|
-
export function setupModuleLoader(window) {
|
|
405
|
-
const $injectorMinErr = minErr("$injector");
|
|
406
|
-
|
|
407
|
-
function ensure(obj, name, factory) {
|
|
408
|
-
return obj[name] || (obj[name] = factory());
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const angular = ensure(window, "angular", Object);
|
|
412
|
-
|
|
413
|
-
// We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap
|
|
414
|
-
angular.$$minErr = angular.$$minErr || minErr;
|
|
415
|
-
|
|
416
|
-
return ensure(angular, "module", () => {
|
|
417
|
-
/** @type {Object.<string, import('./types').Module>} */
|
|
418
|
-
const modules = {};
|
|
419
|
-
|
|
420
|
-
return function module(name, requires, configFn) {
|
|
421
|
-
let info = {};
|
|
422
|
-
|
|
423
|
-
assertNotHasOwnProperty(name, "module");
|
|
424
|
-
if (requires && Object.prototype.hasOwnProperty.call(modules, name)) {
|
|
425
|
-
modules[name] = null;
|
|
426
|
-
}
|
|
427
|
-
return ensure(modules, name, () => {
|
|
428
|
-
if (!requires) {
|
|
429
|
-
throw $injectorMinErr(
|
|
430
|
-
"nomod",
|
|
431
|
-
"Module '{0}' is not available! You either misspelled " +
|
|
432
|
-
"the module name or forgot to load it. If registering a module ensure that you " +
|
|
433
|
-
"specify the dependencies as the second argument.",
|
|
434
|
-
name,
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/** @type {!Array.<Array.<*>>} */
|
|
439
|
-
const invokeQueue = [];
|
|
440
|
-
|
|
441
|
-
/** @type {!Array.<Function>} */
|
|
442
|
-
const configBlocks = [];
|
|
443
|
-
|
|
444
|
-
/** @type {!Array.<Function>} */
|
|
445
|
-
const runBlocks = [];
|
|
446
|
-
|
|
447
|
-
const config = invokeLater("$injector", "invoke", "push", configBlocks);
|
|
448
|
-
|
|
449
|
-
/** @type {import('./types').Module} */
|
|
450
|
-
const moduleInstance = {
|
|
451
|
-
// Private state
|
|
452
|
-
_invokeQueue: invokeQueue,
|
|
453
|
-
_configBlocks: configBlocks,
|
|
454
|
-
_runBlocks: runBlocks,
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* @name import('./types').Module#info
|
|
458
|
-
* @module ng
|
|
459
|
-
*
|
|
460
|
-
* @param {Object=} value Information about the module
|
|
461
|
-
* @returns {Object|import('./types').Module} The current info object for this module if called as a getter,
|
|
462
|
-
* or `this` if called as a setter.
|
|
463
|
-
*
|
|
464
|
-
* Read and write custom information about this module.
|
|
465
|
-
* For example you could put the version of the module in here.
|
|
466
|
-
*
|
|
467
|
-
* ```js
|
|
468
|
-
* angular.module('myModule', []).info({ version: '1.0.0' });
|
|
469
|
-
* ```
|
|
470
|
-
*
|
|
471
|
-
* The version could then be read back out by accessing the module elsewhere:
|
|
472
|
-
*
|
|
473
|
-
* ```
|
|
474
|
-
* let version = angular.module('myModule').info().version;
|
|
475
|
-
* ```
|
|
476
|
-
*
|
|
477
|
-
* You can also retrieve this information during runtime via the
|
|
478
|
-
* {@link $injector#modules `$injector.modules`} property:
|
|
479
|
-
*
|
|
480
|
-
* ```js
|
|
481
|
-
* let version = $injector.modules['myModule'].info().version;
|
|
482
|
-
* ```
|
|
483
|
-
*/
|
|
484
|
-
info(value) {
|
|
485
|
-
if (isDefined(value)) {
|
|
486
|
-
if (!isObject(value))
|
|
487
|
-
throw ngMinErr(
|
|
488
|
-
"aobj",
|
|
489
|
-
"Argument '{0}' must be an object",
|
|
490
|
-
"value",
|
|
491
|
-
);
|
|
492
|
-
info = value;
|
|
493
|
-
return this;
|
|
494
|
-
}
|
|
495
|
-
return info;
|
|
496
|
-
},
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* @ngdoc property
|
|
500
|
-
* @name import('./types').Module#requires
|
|
501
|
-
* @module ng
|
|
502
|
-
*
|
|
503
|
-
* Holds the list of modules which the injector will load before the current module is
|
|
504
|
-
* loaded.
|
|
505
|
-
*/
|
|
506
|
-
requires,
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* @ngdoc property
|
|
510
|
-
* @name import('./types').Module#name
|
|
511
|
-
* @module ng
|
|
512
|
-
*
|
|
513
|
-
* Name of the module.
|
|
514
|
-
*/
|
|
515
|
-
name,
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* @name import('./types').Module#provider
|
|
519
|
-
* @param {string} name service name
|
|
520
|
-
* @param {Function} providerType Construction function for creating new instance of the
|
|
521
|
-
* service.
|
|
522
|
-
* See {@link auto.$provide#provider $provide.provider()}.
|
|
523
|
-
*/
|
|
524
|
-
provider: invokeLaterAndSetModuleName("$provide", "provider"),
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* @name import('./types').Module#factory
|
|
528
|
-
* @param {string} name service name
|
|
529
|
-
* @param {Function} providerFunction Function for creating new instance of the service.
|
|
530
|
-
* See {@link auto.$provide#factory $provide.factory()}.
|
|
531
|
-
*/
|
|
532
|
-
factory: invokeLaterAndSetModuleName("$provide", "factory"),
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* @name import('./types').Module#service
|
|
536
|
-
* @param {string} name service name
|
|
537
|
-
* @param {Function} constructor A constructor function that will be instantiated.
|
|
538
|
-
* See {@link auto.$provide#service $provide.service()}.
|
|
539
|
-
*/
|
|
540
|
-
service: invokeLaterAndSetModuleName("$provide", "service"),
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* @name import('./types').Module#value
|
|
544
|
-
* @param {string} name service name
|
|
545
|
-
* @param {*} object Service instance object.
|
|
546
|
-
* See {@link auto.$provide#value $provide.value()}.
|
|
547
|
-
*/
|
|
548
|
-
value: invokeLater("$provide", "value"),
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* @name import('./types').Module#constant
|
|
552
|
-
* @param {string} name constant name
|
|
553
|
-
* @param {*} object Constant value.
|
|
554
|
-
* Because the constants are fixed, they get applied before other provide methods.
|
|
555
|
-
* See {@link auto.$provide#constant $provide.constant()}.
|
|
556
|
-
*/
|
|
557
|
-
constant: invokeLater("$provide", "constant", "unshift"),
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* @name import('./types').Module#decorator
|
|
561
|
-
* @param {string} name The name of the service to decorate.
|
|
562
|
-
* @param {Function} decorFn This function will be invoked when the service needs to be
|
|
563
|
-
* instantiated and should return the decorated service instance.
|
|
564
|
-
* See {@link auto.$provide#decorator $provide.decorator()}.
|
|
565
|
-
*/
|
|
566
|
-
decorator: invokeLaterAndSetModuleName(
|
|
567
|
-
"$provide",
|
|
568
|
-
"decorator",
|
|
569
|
-
configBlocks,
|
|
570
|
-
),
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* @name import('./types').Module#animation
|
|
574
|
-
* @param {string} name animation name
|
|
575
|
-
* @param {Function} animationFactory Factory function for creating new instance of an
|
|
576
|
-
* animation.
|
|
577
|
-
*
|
|
578
|
-
* **NOTE**: animations take effect only if the **ngAnimate** module is loaded.
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* Defines an animation hook that can be later used with
|
|
582
|
-
* {@link $animate $animate} service and directives that use this service.
|
|
583
|
-
*
|
|
584
|
-
* ```js
|
|
585
|
-
* module.animation('.animation-name', function($inject1, $inject2) {
|
|
586
|
-
* return {
|
|
587
|
-
* eventName : function(element, done) {
|
|
588
|
-
* //code to run the animation
|
|
589
|
-
* //once complete, then run done()
|
|
590
|
-
* return function cancellationFunction(element) {
|
|
591
|
-
* //code to cancel the animation
|
|
592
|
-
* }
|
|
593
|
-
* }
|
|
594
|
-
* }
|
|
595
|
-
* })
|
|
596
|
-
* ```
|
|
597
|
-
*
|
|
598
|
-
* See {@link ng.$animateProvider#register $animateProvider.register()} and
|
|
599
|
-
* {@link ngAnimate ngAnimate module} for more information.
|
|
600
|
-
*/
|
|
601
|
-
animation: invokeLaterAndSetModuleName(
|
|
602
|
-
"$animateProvider",
|
|
603
|
-
"register",
|
|
604
|
-
),
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* @name import('./types').Module#filter
|
|
608
|
-
* @param {string} name Filter name - this must be a valid AngularJS expression identifier
|
|
609
|
-
* @param {Function} filterFactory Factory function for creating new instance of filter.
|
|
610
|
-
* See {@link ng.$filterProvider#register $filterProvider.register()}.
|
|
611
|
-
*
|
|
612
|
-
* <div class="alert alert-warning">
|
|
613
|
-
* **Note:** Filter names must be valid AngularJS {@link expression} identifiers, such as `uppercase` or `orderBy`.
|
|
614
|
-
* Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
|
|
615
|
-
* your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
|
|
616
|
-
* (`myapp_subsection_filterx`).
|
|
617
|
-
* </div>
|
|
618
|
-
*/
|
|
619
|
-
filter: invokeLaterAndSetModuleName("$filterProvider", "register"),
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* @name import('./types').Module#controller
|
|
623
|
-
* @param {string|Object} name Controller name, or an object map of controllers where the
|
|
624
|
-
* keys are the names and the values are the constructors.
|
|
625
|
-
* @param {Function} constructor Controller constructor function.
|
|
626
|
-
* See {@link ng.$controllerProvider#register $controllerProvider.register()}.
|
|
627
|
-
*/
|
|
628
|
-
controller: invokeLaterAndSetModuleName(
|
|
629
|
-
"$controllerProvider",
|
|
630
|
-
"register",
|
|
631
|
-
),
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* @name import('./types').Module#directive
|
|
635
|
-
* @param {string|Object} name Directive name, or an object map of directives where the
|
|
636
|
-
* keys are the names and the values are the factories.
|
|
637
|
-
* @param {Function} directiveFactory Factory function for creating new instance of
|
|
638
|
-
* directives.
|
|
639
|
-
* See {@link ng.$compileProvider#directive $compileProvider.directive()}.
|
|
640
|
-
*/
|
|
641
|
-
directive: invokeLaterAndSetModuleName(
|
|
642
|
-
"$compileProvider",
|
|
643
|
-
"directive",
|
|
644
|
-
),
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
* @name import('./types').Module#component
|
|
648
|
-
* @param {string|Object} name Name of the component in camelCase (i.e. `myComp` which will match `<my-comp>`),
|
|
649
|
-
* or an object map of components where the keys are the names and the values are the component definition objects.
|
|
650
|
-
* @param {Object} options Component definition object (a simplified
|
|
651
|
-
* {@link ng.$compile#directive-definition-object directive definition object})
|
|
652
|
-
*
|
|
653
|
-
* See {@link ng.$compileProvider#component $compileProvider.component()}.
|
|
654
|
-
*/
|
|
655
|
-
component: invokeLaterAndSetModuleName(
|
|
656
|
-
"$compileProvider",
|
|
657
|
-
"component",
|
|
658
|
-
),
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* @name import('./types').Module#config
|
|
662
|
-
* @param {Function} configFn Execute this function on module load. Useful for service
|
|
663
|
-
* configuration.
|
|
664
|
-
* Use this method to configure services by injecting their
|
|
665
|
-
* {@link import('./types').Module#provider `providers`}, e.g. for adding routes to the
|
|
666
|
-
* {@link ngRoute.$routeProvider $routeProvider}.
|
|
667
|
-
*
|
|
668
|
-
* Note that you can only inject {@link import('./types').Module#provider `providers`} and
|
|
669
|
-
* {@link import('./types').Module#constant `constants`} into this function.
|
|
670
|
-
*
|
|
671
|
-
* For more about how to configure services, see
|
|
672
|
-
* {@link providers#provider-recipe Provider Recipe}.
|
|
673
|
-
*/
|
|
674
|
-
config,
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* @name import('./types').Module#run
|
|
678
|
-
* @param {Function} block Execute this function after injector creation.
|
|
679
|
-
* Useful for application initialization.
|
|
680
|
-
* Use this method to register work which should be performed when the injector is done
|
|
681
|
-
* loading all modules.
|
|
682
|
-
*/
|
|
683
|
-
run(block) {
|
|
684
|
-
runBlocks.push(block);
|
|
685
|
-
return this;
|
|
686
|
-
},
|
|
687
|
-
};
|
|
688
|
-
|
|
689
|
-
if (configFn) {
|
|
690
|
-
config(configFn);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
return moduleInstance;
|
|
694
|
-
|
|
695
|
-
/**
|
|
696
|
-
* @param {string} provider
|
|
697
|
-
* @param {string} method
|
|
698
|
-
* @param {String=} [insertMethod]
|
|
699
|
-
* @param {Array<any>} [queue]
|
|
700
|
-
* @returns {import('./types').Module}
|
|
701
|
-
*/
|
|
702
|
-
function invokeLater(provider, method, insertMethod, queue) {
|
|
703
|
-
if (!queue) queue = invokeQueue;
|
|
704
|
-
return function () {
|
|
705
|
-
queue[insertMethod || "push"]([provider, method, arguments]);
|
|
706
|
-
return moduleInstance;
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* @param {string} provider
|
|
712
|
-
* @param {string} method
|
|
713
|
-
* @returns {import('./types').Module}
|
|
714
|
-
*/
|
|
715
|
-
function invokeLaterAndSetModuleName(provider, method, queue) {
|
|
716
|
-
if (!queue) queue = invokeQueue;
|
|
717
|
-
return function (recipeName, factoryFunction) {
|
|
718
|
-
if (factoryFunction && isFunction(factoryFunction))
|
|
719
|
-
factoryFunction.$$moduleName = name;
|
|
720
|
-
queue.push([provider, method, arguments]);
|
|
721
|
-
return moduleInstance;
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
};
|
|
726
|
-
});
|
|
293
|
+
function ensure(obj, name, factory) {
|
|
294
|
+
return obj[name] || (obj[name] = factory());
|
|
727
295
|
}
|