@angular/upgrade 21.0.0-next.0 → 21.0.0-next.10

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.
@@ -1,793 +1,1189 @@
1
1
  /**
2
- * @license Angular v21.0.0-next.0
3
- * (c) 2010-2025 Google LLC. https://angular.io/
2
+ * @license Angular v21.0.0-next.10
3
+ * (c) 2010-2025 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import { module_, UPGRADE_APP_TYPE_KEY, INJECTOR_KEY, LAZY_MODULE_REF, $INJECTOR, $PROVIDE, DOWNGRADED_MODULE_COUNT_KEY, UPGRADE_MODULE_NAME, $SCOPE, $$TESTABILITY, $DELEGATE, $INTERVAL, element, bootstrap } from './constants.mjs';
8
- export { getAngularJSGlobal, getAngularLib, setAngularJSGlobal, setAngularLib, angular1 as ɵangular1, constants as ɵconstants } from './constants.mjs';
9
- import { destroyApp, getDowngradedModuleCount, isNgModuleType, isFunction, UpgradeHelper, controllerKey } from './upgrade_helper.mjs';
10
- export { VERSION, downgradeComponent, downgradeInjectable, upgrade_helper as ɵupgradeHelper, util as ɵutil } from './upgrade_helper.mjs';
7
+ import { element, $ROOT_ELEMENT, $ROOT_SCOPE, DOWNGRADED_MODULE_COUNT_KEY, UPGRADE_APP_TYPE_KEY, $SCOPE, $COMPILE, $INJECTOR, $PARSE, REQUIRE_INJECTOR, REQUIRE_NG_MODEL, LAZY_MODULE_REF, INJECTOR_KEY, $CONTROLLER, $TEMPLATE_CACHE, $HTTP_BACKEND, module_, $PROVIDE, UPGRADE_MODULE_NAME, $$TESTABILITY, $DELEGATE, $INTERVAL, bootstrap } from './_constants-chunk.mjs';
8
+ export { getAngularJSGlobal, getAngularLib, setAngularJSGlobal, setAngularLib, angular1 as ɵangular1, constants as ɵconstants } from './_constants-chunk.mjs';
11
9
  import * as i0 from '@angular/core';
12
- import { ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as _NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, PlatformRef, EventEmitter, Directive, ApplicationRef, ɵNoopNgZone as _NoopNgZone, NgModule, Testability } from '@angular/core';
10
+ import { ɵNG_MOD_DEF as _NG_MOD_DEF, Injector, ChangeDetectorRef, Testability, TestabilityRegistry, ApplicationRef, SimpleChange, ɵSIGNAL as _SIGNAL, NgZone, ComponentFactoryResolver, ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as _NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR, PlatformRef, ɵinternalProvideZoneChangeDetection as _internalProvideZoneChangeDetection, EventEmitter, Directive, ɵNoopNgZone as _NoopNgZone, NgModule } from '@angular/core';
11
+ export { VERSION } from './upgrade.mjs';
13
12
  import { platformBrowser } from '@angular/platform-browser';
14
13
 
15
- // We have to do a little dance to get the ng1 injector into the module injector.
16
- // We store the ng1 injector so that the provider in the module injector can access it
17
- // Then we "get" the ng1 injector from the module injector, which triggers the provider to read
18
- // the stored injector and release the reference to it.
14
+ class PropertyBinding {
15
+ prop;
16
+ attr;
17
+ bracketAttr;
18
+ bracketParenAttr;
19
+ parenAttr;
20
+ onAttr;
21
+ bindAttr;
22
+ bindonAttr;
23
+ constructor(prop, attr) {
24
+ this.prop = prop;
25
+ this.attr = attr;
26
+ this.bracketAttr = `[${this.attr}]`;
27
+ this.parenAttr = `(${this.attr})`;
28
+ this.bracketParenAttr = `[(${this.attr})]`;
29
+ const capitalAttr = this.attr.charAt(0).toUpperCase() + this.attr.slice(1);
30
+ this.onAttr = `on${capitalAttr}`;
31
+ this.bindAttr = `bind${capitalAttr}`;
32
+ this.bindonAttr = `bindon${capitalAttr}`;
33
+ }
34
+ }
35
+
36
+ const DIRECTIVE_PREFIX_REGEXP = /^(?:x|data)[:\-_]/i;
37
+ const DIRECTIVE_SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
38
+ function onError(e) {
39
+ console.error(e, e.stack);
40
+ throw e;
41
+ }
42
+ function cleanData(node) {
43
+ element.cleanData([node]);
44
+ if (isParentNode(node)) {
45
+ element.cleanData(node.querySelectorAll('*'));
46
+ }
47
+ }
48
+ function controllerKey(name) {
49
+ return '$' + name + 'Controller';
50
+ }
51
+ function destroyApp($injector) {
52
+ const $rootElement = $injector.get($ROOT_ELEMENT);
53
+ const $rootScope = $injector.get($ROOT_SCOPE);
54
+ $rootScope.$destroy();
55
+ cleanData($rootElement[0]);
56
+ }
57
+ function directiveNormalize(name) {
58
+ return name.replace(DIRECTIVE_PREFIX_REGEXP, '').replace(DIRECTIVE_SPECIAL_CHARS_REGEXP, (_, letter) => letter.toUpperCase());
59
+ }
60
+ function getTypeName(type) {
61
+ return type.overriddenName || type.name || type.toString().split('\n')[0];
62
+ }
63
+ function getDowngradedModuleCount($injector) {
64
+ return $injector.has(DOWNGRADED_MODULE_COUNT_KEY) ? $injector.get(DOWNGRADED_MODULE_COUNT_KEY) : 0;
65
+ }
66
+ function getUpgradeAppType($injector) {
67
+ return $injector.has(UPGRADE_APP_TYPE_KEY) ? $injector.get(UPGRADE_APP_TYPE_KEY) : 0;
68
+ }
69
+ function isFunction(value) {
70
+ return typeof value === 'function';
71
+ }
72
+ function isNgModuleType(value) {
73
+ return isFunction(value) && !!value[_NG_MOD_DEF];
74
+ }
75
+ function isParentNode(node) {
76
+ return isFunction(node.querySelectorAll);
77
+ }
78
+ function validateInjectionKey($injector, downgradedModule, injectionKey, attemptedAction) {
79
+ const upgradeAppType = getUpgradeAppType($injector);
80
+ const downgradedModuleCount = getDowngradedModuleCount($injector);
81
+ switch (upgradeAppType) {
82
+ case 1:
83
+ case 2:
84
+ if (downgradedModule) {
85
+ throw new Error(`Error while ${attemptedAction}: 'downgradedModule' unexpectedly specified.\n` + "You should not specify a value for 'downgradedModule', unless you are downgrading " + "more than one Angular module (via 'downgradeModule()').");
86
+ }
87
+ break;
88
+ case 3:
89
+ if (!downgradedModule && downgradedModuleCount >= 2) {
90
+ throw new Error(`Error while ${attemptedAction}: 'downgradedModule' not specified.\n` + 'This application contains more than one downgraded Angular module, thus you need to ' + "always specify 'downgradedModule' when downgrading components and injectables.");
91
+ }
92
+ if (!$injector.has(injectionKey)) {
93
+ throw new Error(`Error while ${attemptedAction}: Unable to find the specified downgraded module.\n` + 'Did you forget to downgrade an Angular module or include it in the AngularJS ' + 'application?');
94
+ }
95
+ break;
96
+ default:
97
+ throw new Error(`Error while ${attemptedAction}: Not a valid '@angular/upgrade' application.\n` + 'Did you forget to downgrade an Angular module or include it in the AngularJS ' + 'application?');
98
+ }
99
+ }
100
+ class Deferred {
101
+ promise;
102
+ resolve;
103
+ reject;
104
+ constructor() {
105
+ this.promise = new Promise((res, rej) => {
106
+ this.resolve = res;
107
+ this.reject = rej;
108
+ });
109
+ }
110
+ }
111
+ function supportsNgModel(component) {
112
+ return typeof component.writeValue === 'function' && typeof component.registerOnChange === 'function';
113
+ }
114
+ function hookupNgModel(ngModel, component) {
115
+ if (ngModel && supportsNgModel(component)) {
116
+ ngModel.$render = () => {
117
+ component.writeValue(ngModel.$viewValue);
118
+ };
119
+ component.registerOnChange(ngModel.$setViewValue.bind(ngModel));
120
+ if (typeof component.registerOnTouched === 'function') {
121
+ component.registerOnTouched(ngModel.$setTouched.bind(ngModel));
122
+ }
123
+ }
124
+ }
125
+ function strictEquals(val1, val2) {
126
+ return val1 === val2 || val1 !== val1 && val2 !== val2;
127
+ }
128
+
129
+ var util = /*#__PURE__*/Object.freeze({
130
+ __proto__: null,
131
+ Deferred: Deferred,
132
+ cleanData: cleanData,
133
+ controllerKey: controllerKey,
134
+ destroyApp: destroyApp,
135
+ directiveNormalize: directiveNormalize,
136
+ getDowngradedModuleCount: getDowngradedModuleCount,
137
+ getTypeName: getTypeName,
138
+ getUpgradeAppType: getUpgradeAppType,
139
+ hookupNgModel: hookupNgModel,
140
+ isFunction: isFunction,
141
+ isNgModuleType: isNgModuleType,
142
+ onError: onError,
143
+ strictEquals: strictEquals,
144
+ validateInjectionKey: validateInjectionKey
145
+ });
146
+
147
+ const INITIAL_VALUE$1 = {
148
+ __UNINITIALIZED__: true
149
+ };
150
+ class DowngradeComponentAdapter {
151
+ element;
152
+ attrs;
153
+ scope;
154
+ ngModel;
155
+ parentInjector;
156
+ $compile;
157
+ $parse;
158
+ componentFactory;
159
+ wrapCallback;
160
+ unsafelyOverwriteSignalInputs;
161
+ implementsOnChanges = false;
162
+ inputChangeCount = 0;
163
+ inputChanges = {};
164
+ componentScope;
165
+ constructor(element, attrs, scope, ngModel, parentInjector, $compile, $parse, componentFactory, wrapCallback, unsafelyOverwriteSignalInputs) {
166
+ this.element = element;
167
+ this.attrs = attrs;
168
+ this.scope = scope;
169
+ this.ngModel = ngModel;
170
+ this.parentInjector = parentInjector;
171
+ this.$compile = $compile;
172
+ this.$parse = $parse;
173
+ this.componentFactory = componentFactory;
174
+ this.wrapCallback = wrapCallback;
175
+ this.unsafelyOverwriteSignalInputs = unsafelyOverwriteSignalInputs;
176
+ this.componentScope = scope.$new();
177
+ }
178
+ compileContents() {
179
+ const compiledProjectableNodes = [];
180
+ const projectableNodes = this.groupProjectableNodes();
181
+ const linkFns = projectableNodes.map(nodes => this.$compile(nodes));
182
+ this.element.empty();
183
+ linkFns.forEach(linkFn => {
184
+ linkFn(this.scope, clone => {
185
+ compiledProjectableNodes.push(clone);
186
+ this.element.append(clone);
187
+ });
188
+ });
189
+ return compiledProjectableNodes;
190
+ }
191
+ createComponentAndSetup(projectableNodes, manuallyAttachView = false, propagateDigest = true) {
192
+ const component = this.createComponent(projectableNodes);
193
+ this.setupInputs(manuallyAttachView, propagateDigest, component);
194
+ this.setupOutputs(component.componentRef);
195
+ this.registerCleanup(component.componentRef);
196
+ return component.componentRef;
197
+ }
198
+ createComponent(projectableNodes) {
199
+ const providers = [{
200
+ provide: $SCOPE,
201
+ useValue: this.componentScope
202
+ }];
203
+ const childInjector = Injector.create({
204
+ providers: providers,
205
+ parent: this.parentInjector,
206
+ name: 'DowngradeComponentAdapter'
207
+ });
208
+ const componentRef = this.componentFactory.create(childInjector, projectableNodes, this.element[0]);
209
+ const viewChangeDetector = componentRef.injector.get(ChangeDetectorRef);
210
+ const changeDetector = componentRef.changeDetectorRef;
211
+ const testability = componentRef.injector.get(Testability, null);
212
+ if (testability) {
213
+ componentRef.injector.get(TestabilityRegistry).registerApplication(componentRef.location.nativeElement, testability);
214
+ }
215
+ hookupNgModel(this.ngModel, componentRef.instance);
216
+ return {
217
+ viewChangeDetector,
218
+ componentRef,
219
+ changeDetector
220
+ };
221
+ }
222
+ setupInputs(manuallyAttachView, propagateDigest = true, {
223
+ componentRef,
224
+ changeDetector,
225
+ viewChangeDetector
226
+ }) {
227
+ const attrs = this.attrs;
228
+ const inputs = this.componentFactory.inputs || [];
229
+ for (const input of inputs) {
230
+ const inputBinding = new PropertyBinding(input.propName, input.templateName);
231
+ let expr = null;
232
+ if (attrs.hasOwnProperty(inputBinding.attr)) {
233
+ const observeFn = ((prop, isSignal) => {
234
+ let prevValue = INITIAL_VALUE$1;
235
+ return currValue => {
236
+ if (!strictEquals(prevValue, currValue)) {
237
+ if (prevValue === INITIAL_VALUE$1) {
238
+ prevValue = currValue;
239
+ }
240
+ this.updateInput(componentRef, prop, prevValue, currValue, isSignal);
241
+ prevValue = currValue;
242
+ }
243
+ };
244
+ })(inputBinding.prop, input.isSignal);
245
+ attrs.$observe(inputBinding.attr, observeFn);
246
+ let unwatch = this.componentScope.$watch(() => {
247
+ unwatch();
248
+ unwatch = null;
249
+ observeFn(attrs[inputBinding.attr]);
250
+ });
251
+ } else if (attrs.hasOwnProperty(inputBinding.bindAttr)) {
252
+ expr = attrs[inputBinding.bindAttr];
253
+ } else if (attrs.hasOwnProperty(inputBinding.bracketAttr)) {
254
+ expr = attrs[inputBinding.bracketAttr];
255
+ } else if (attrs.hasOwnProperty(inputBinding.bindonAttr)) {
256
+ expr = attrs[inputBinding.bindonAttr];
257
+ } else if (attrs.hasOwnProperty(inputBinding.bracketParenAttr)) {
258
+ expr = attrs[inputBinding.bracketParenAttr];
259
+ }
260
+ if (expr != null) {
261
+ const watchFn = ((prop, isSignal) => (currValue, prevValue) => this.updateInput(componentRef, prop, prevValue, currValue, isSignal))(inputBinding.prop, input.isSignal);
262
+ this.componentScope.$watch(expr, watchFn);
263
+ }
264
+ }
265
+ const detectChanges = () => changeDetector.detectChanges();
266
+ const prototype = this.componentFactory.componentType.prototype;
267
+ this.implementsOnChanges = !!(prototype && prototype.ngOnChanges);
268
+ this.componentScope.$watch(() => this.inputChangeCount, this.wrapCallback(() => {
269
+ if (this.implementsOnChanges) {
270
+ const inputChanges = this.inputChanges;
271
+ this.inputChanges = {};
272
+ componentRef.instance.ngOnChanges(inputChanges);
273
+ }
274
+ viewChangeDetector.markForCheck();
275
+ if (!propagateDigest) {
276
+ detectChanges();
277
+ }
278
+ }));
279
+ if (propagateDigest) {
280
+ this.componentScope.$watch(this.wrapCallback(detectChanges));
281
+ }
282
+ if (manuallyAttachView || !propagateDigest) {
283
+ let unwatch = this.componentScope.$watch(() => {
284
+ unwatch();
285
+ unwatch = null;
286
+ const appRef = this.parentInjector.get(ApplicationRef);
287
+ appRef.attachView(componentRef.hostView);
288
+ });
289
+ }
290
+ }
291
+ setupOutputs(componentRef) {
292
+ const attrs = this.attrs;
293
+ const outputs = this.componentFactory.outputs || [];
294
+ for (const output of outputs) {
295
+ const outputBindings = new PropertyBinding(output.propName, output.templateName);
296
+ const bindonAttr = outputBindings.bindonAttr.substring(0, outputBindings.bindonAttr.length - 6);
297
+ const bracketParenAttr = `[(${outputBindings.bracketParenAttr.substring(2, outputBindings.bracketParenAttr.length - 8)})]`;
298
+ if (attrs.hasOwnProperty(bindonAttr)) {
299
+ this.subscribeToOutput(componentRef, outputBindings, attrs[bindonAttr], true);
300
+ }
301
+ if (attrs.hasOwnProperty(bracketParenAttr)) {
302
+ this.subscribeToOutput(componentRef, outputBindings, attrs[bracketParenAttr], true);
303
+ }
304
+ if (attrs.hasOwnProperty(outputBindings.onAttr)) {
305
+ this.subscribeToOutput(componentRef, outputBindings, attrs[outputBindings.onAttr]);
306
+ }
307
+ if (attrs.hasOwnProperty(outputBindings.parenAttr)) {
308
+ this.subscribeToOutput(componentRef, outputBindings, attrs[outputBindings.parenAttr]);
309
+ }
310
+ }
311
+ }
312
+ subscribeToOutput(componentRef, output, expr, isAssignment = false) {
313
+ const getter = this.$parse(expr);
314
+ const setter = getter.assign;
315
+ if (isAssignment && !setter) {
316
+ throw new Error(`Expression '${expr}' is not assignable!`);
317
+ }
318
+ const emitter = componentRef.instance[output.prop];
319
+ if (emitter) {
320
+ const subscription = emitter.subscribe(isAssignment ? v => setter(this.scope, v) : v => getter(this.scope, {
321
+ '$event': v
322
+ }));
323
+ componentRef.onDestroy(() => subscription.unsubscribe());
324
+ } else {
325
+ throw new Error(`Missing emitter '${output.prop}' on component '${getTypeName(this.componentFactory.componentType)}'!`);
326
+ }
327
+ }
328
+ registerCleanup(componentRef) {
329
+ const testabilityRegistry = componentRef.injector.get(TestabilityRegistry);
330
+ const destroyComponentRef = this.wrapCallback(() => componentRef.destroy());
331
+ let destroyed = false;
332
+ this.element.on('$destroy', () => {
333
+ if (!destroyed) this.componentScope.$destroy();
334
+ });
335
+ this.componentScope.$on('$destroy', () => {
336
+ if (!destroyed) {
337
+ destroyed = true;
338
+ testabilityRegistry.unregisterApplication(componentRef.location.nativeElement);
339
+ cleanData(this.element[0]);
340
+ destroyComponentRef();
341
+ }
342
+ });
343
+ }
344
+ updateInput(componentRef, prop, prevValue, currValue, isSignal) {
345
+ if (this.implementsOnChanges) {
346
+ this.inputChanges[prop] = new SimpleChange(prevValue, currValue, prevValue === currValue);
347
+ }
348
+ this.inputChangeCount++;
349
+ if (isSignal && !this.unsafelyOverwriteSignalInputs) {
350
+ const node = componentRef.instance[prop][_SIGNAL];
351
+ node.applyValueToInputSignal(node, currValue);
352
+ } else {
353
+ componentRef.instance[prop] = currValue;
354
+ }
355
+ }
356
+ groupProjectableNodes() {
357
+ let ngContentSelectors = this.componentFactory.ngContentSelectors;
358
+ return groupNodesBySelector(ngContentSelectors, this.element.contents());
359
+ }
360
+ }
361
+ function groupNodesBySelector(ngContentSelectors, nodes) {
362
+ const projectableNodes = [];
363
+ for (let i = 0, ii = ngContentSelectors.length; i < ii; ++i) {
364
+ projectableNodes[i] = [];
365
+ }
366
+ for (let j = 0, jj = nodes.length; j < jj; ++j) {
367
+ const node = nodes[j];
368
+ const ngContentIndex = findMatchingNgContentIndex(node, ngContentSelectors);
369
+ if (ngContentIndex != null) {
370
+ projectableNodes[ngContentIndex].push(node);
371
+ }
372
+ }
373
+ return projectableNodes;
374
+ }
375
+ function findMatchingNgContentIndex(element, ngContentSelectors) {
376
+ const ngContentIndices = [];
377
+ let wildcardNgContentIndex = -1;
378
+ for (let i = 0; i < ngContentSelectors.length; i++) {
379
+ const selector = ngContentSelectors[i];
380
+ if (selector === '*') {
381
+ wildcardNgContentIndex = i;
382
+ } else {
383
+ if (matchesSelector(element, selector)) {
384
+ ngContentIndices.push(i);
385
+ }
386
+ }
387
+ }
388
+ ngContentIndices.sort();
389
+ if (wildcardNgContentIndex !== -1) {
390
+ ngContentIndices.push(wildcardNgContentIndex);
391
+ }
392
+ return ngContentIndices.length ? ngContentIndices[0] : null;
393
+ }
394
+ function matchesSelector(el, selector) {
395
+ const elProto = Element.prototype;
396
+ return el.nodeType === Node.ELEMENT_NODE ? (elProto.matches ?? elProto.msMatchesSelector).call(el, selector) : false;
397
+ }
398
+
399
+ function isThenable(obj) {
400
+ return !!obj && isFunction(obj.then);
401
+ }
402
+ class SyncPromise {
403
+ value;
404
+ resolved = false;
405
+ callbacks = [];
406
+ static all(valuesOrPromises) {
407
+ const aggrPromise = new SyncPromise();
408
+ let resolvedCount = 0;
409
+ const results = [];
410
+ const resolve = (idx, value) => {
411
+ results[idx] = value;
412
+ if (++resolvedCount === valuesOrPromises.length) aggrPromise.resolve(results);
413
+ };
414
+ valuesOrPromises.forEach((p, idx) => {
415
+ if (isThenable(p)) {
416
+ p.then(v => resolve(idx, v));
417
+ } else {
418
+ resolve(idx, p);
419
+ }
420
+ });
421
+ return aggrPromise;
422
+ }
423
+ resolve(value) {
424
+ if (this.resolved) return;
425
+ this.value = value;
426
+ this.resolved = true;
427
+ this.callbacks.forEach(callback => callback(value));
428
+ this.callbacks.length = 0;
429
+ }
430
+ then(callback) {
431
+ if (this.resolved) {
432
+ callback(this.value);
433
+ } else {
434
+ this.callbacks.push(callback);
435
+ }
436
+ }
437
+ }
438
+
439
+ function downgradeComponent(info) {
440
+ const directiveFactory = function ($compile, $injector, $parse) {
441
+ const unsafelyOverwriteSignalInputs = info.unsafelyOverwriteSignalInputs ?? false;
442
+ const isNgUpgradeLite = getUpgradeAppType($injector) === 3;
443
+ const wrapCallback = !isNgUpgradeLite ? cb => cb : cb => () => NgZone.isInAngularZone() ? cb() : ngZone.run(cb);
444
+ let ngZone;
445
+ const hasMultipleDowngradedModules = isNgUpgradeLite && getDowngradedModuleCount($injector) > 1;
446
+ return {
447
+ restrict: 'E',
448
+ terminal: true,
449
+ require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
450
+ controller: function () {},
451
+ link: (scope, element, attrs, required) => {
452
+ const ngModel = required[1];
453
+ const parentInjector = required[0];
454
+ let moduleInjector = undefined;
455
+ let ranAsync = false;
456
+ if (!parentInjector || hasMultipleDowngradedModules) {
457
+ const downgradedModule = info.downgradedModule || '';
458
+ const lazyModuleRefKey = `${LAZY_MODULE_REF}${downgradedModule}`;
459
+ const attemptedAction = `instantiating component '${getTypeName(info.component)}'`;
460
+ validateInjectionKey($injector, downgradedModule, lazyModuleRefKey, attemptedAction);
461
+ const lazyModuleRef = $injector.get(lazyModuleRefKey);
462
+ moduleInjector = lazyModuleRef.injector ?? lazyModuleRef.promise;
463
+ }
464
+ const finalParentInjector = parentInjector || moduleInjector;
465
+ const finalModuleInjector = moduleInjector || parentInjector;
466
+ const doDowngrade = (injector, moduleInjector) => {
467
+ const componentFactoryResolver = moduleInjector.get(ComponentFactoryResolver);
468
+ const componentFactory = componentFactoryResolver.resolveComponentFactory(info.component);
469
+ if (!componentFactory) {
470
+ throw new Error(`Expecting ComponentFactory for: ${getTypeName(info.component)}`);
471
+ }
472
+ const injectorPromise = new ParentInjectorPromise(element);
473
+ const facade = new DowngradeComponentAdapter(element, attrs, scope, ngModel, injector, $compile, $parse, componentFactory, wrapCallback, unsafelyOverwriteSignalInputs);
474
+ const projectableNodes = facade.compileContents();
475
+ const componentRef = facade.createComponentAndSetup(projectableNodes, isNgUpgradeLite, info.propagateDigest);
476
+ injectorPromise.resolve(componentRef.injector);
477
+ if (ranAsync) {
478
+ scope.$evalAsync(() => {});
479
+ }
480
+ };
481
+ const downgradeFn = !isNgUpgradeLite ? doDowngrade : (pInjector, mInjector) => {
482
+ if (!ngZone) {
483
+ ngZone = pInjector.get(NgZone);
484
+ }
485
+ wrapCallback(() => doDowngrade(pInjector, mInjector))();
486
+ };
487
+ SyncPromise.all([finalParentInjector, finalModuleInjector]).then(([pInjector, mInjector]) => downgradeFn(pInjector, mInjector));
488
+ ranAsync = true;
489
+ }
490
+ };
491
+ };
492
+ directiveFactory['$inject'] = [$COMPILE, $INJECTOR, $PARSE];
493
+ return directiveFactory;
494
+ }
495
+ class ParentInjectorPromise extends SyncPromise {
496
+ element;
497
+ injectorKey = controllerKey(INJECTOR_KEY);
498
+ constructor(element) {
499
+ super();
500
+ this.element = element;
501
+ element.data(this.injectorKey, this);
502
+ }
503
+ resolve(injector) {
504
+ this.element.data(this.injectorKey, injector);
505
+ this.element = null;
506
+ super.resolve(injector);
507
+ }
508
+ }
509
+
510
+ function downgradeInjectable(token, downgradedModule = '') {
511
+ const factory = function ($injector) {
512
+ const injectorKey = `${INJECTOR_KEY}${downgradedModule}`;
513
+ const injectableName = isFunction(token) ? getTypeName(token) : String(token);
514
+ const attemptedAction = `instantiating injectable '${injectableName}'`;
515
+ validateInjectionKey($injector, downgradedModule, injectorKey, attemptedAction);
516
+ try {
517
+ const injector = $injector.get(injectorKey);
518
+ return injector.get(token);
519
+ } catch (err) {
520
+ throw new Error(`Error while ${attemptedAction}: ${err.message || err}`);
521
+ }
522
+ };
523
+ factory['$inject'] = [$INJECTOR];
524
+ return factory;
525
+ }
526
+
527
+ let policy;
528
+ function getPolicy() {
529
+ if (policy === undefined) {
530
+ policy = null;
531
+ const windowWithTrustedTypes = window;
532
+ if (windowWithTrustedTypes.trustedTypes) {
533
+ try {
534
+ policy = windowWithTrustedTypes.trustedTypes.createPolicy('angular#unsafe-upgrade', {
535
+ createHTML: s => s
536
+ });
537
+ } catch {}
538
+ }
539
+ }
540
+ return policy;
541
+ }
542
+ function trustedHTMLFromLegacyTemplate(html) {
543
+ return getPolicy()?.createHTML(html) || html;
544
+ }
545
+
546
+ const REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
547
+ class UpgradeHelper {
548
+ name;
549
+ $injector;
550
+ element;
551
+ $element;
552
+ directive;
553
+ $compile;
554
+ $controller;
555
+ constructor(injector, name, elementRef, directive) {
556
+ this.name = name;
557
+ this.$injector = injector.get($INJECTOR);
558
+ this.$compile = this.$injector.get($COMPILE);
559
+ this.$controller = this.$injector.get($CONTROLLER);
560
+ this.element = elementRef.nativeElement;
561
+ this.$element = element(this.element);
562
+ this.directive = directive ?? UpgradeHelper.getDirective(this.$injector, name);
563
+ }
564
+ static getDirective($injector, name) {
565
+ const directives = $injector.get(name + 'Directive');
566
+ if (directives.length > 1) {
567
+ throw new Error(`Only support single directive definition for: ${name}`);
568
+ }
569
+ const directive = directives[0];
570
+ if (directive.compile && !directive.link) notSupported(name, 'compile');
571
+ if (directive.replace) notSupported(name, 'replace');
572
+ if (directive.terminal) notSupported(name, 'terminal');
573
+ return directive;
574
+ }
575
+ static getTemplate($injector, directive, fetchRemoteTemplate = false, $element) {
576
+ if (directive.template !== undefined) {
577
+ return trustedHTMLFromLegacyTemplate(getOrCall(directive.template, $element));
578
+ } else if (directive.templateUrl) {
579
+ const $templateCache = $injector.get($TEMPLATE_CACHE);
580
+ const url = getOrCall(directive.templateUrl, $element);
581
+ const template = $templateCache.get(url);
582
+ if (template !== undefined) {
583
+ return trustedHTMLFromLegacyTemplate(template);
584
+ } else if (!fetchRemoteTemplate) {
585
+ throw new Error('loading directive templates asynchronously is not supported');
586
+ }
587
+ return new Promise((resolve, reject) => {
588
+ const $httpBackend = $injector.get($HTTP_BACKEND);
589
+ $httpBackend('GET', url, null, (status, response) => {
590
+ if (status === 200) {
591
+ resolve(trustedHTMLFromLegacyTemplate($templateCache.put(url, response)));
592
+ } else {
593
+ reject(`GET component template from '${url}' returned '${status}: ${response}'`);
594
+ }
595
+ });
596
+ });
597
+ } else {
598
+ throw new Error(`Directive '${directive.name}' is not a component, it is missing template.`);
599
+ }
600
+ }
601
+ buildController(controllerType, $scope) {
602
+ const locals = {
603
+ '$scope': $scope,
604
+ '$element': this.$element
605
+ };
606
+ const controller = this.$controller(controllerType, locals, null, this.directive.controllerAs);
607
+ this.$element.data?.(controllerKey(this.directive.name), controller);
608
+ return controller;
609
+ }
610
+ compileTemplate(template) {
611
+ if (template === undefined) {
612
+ template = UpgradeHelper.getTemplate(this.$injector, this.directive, false, this.$element);
613
+ }
614
+ return this.compileHtml(template);
615
+ }
616
+ onDestroy($scope, controllerInstance) {
617
+ if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
618
+ controllerInstance.$onDestroy();
619
+ }
620
+ $scope.$destroy();
621
+ cleanData(this.element);
622
+ }
623
+ prepareTransclusion() {
624
+ const transclude = this.directive.transclude;
625
+ const contentChildNodes = this.extractChildNodes();
626
+ const attachChildrenFn = (scope, cloneAttachFn) => {
627
+ scope = scope || {
628
+ $destroy: () => undefined
629
+ };
630
+ return cloneAttachFn($template, scope);
631
+ };
632
+ let $template = contentChildNodes;
633
+ if (transclude) {
634
+ const slots = Object.create(null);
635
+ if (typeof transclude === 'object') {
636
+ $template = [];
637
+ const slotMap = Object.create(null);
638
+ const filledSlots = Object.create(null);
639
+ Object.keys(transclude).forEach(slotName => {
640
+ let selector = transclude[slotName];
641
+ const optional = selector.charAt(0) === '?';
642
+ selector = optional ? selector.substring(1) : selector;
643
+ slotMap[selector] = slotName;
644
+ slots[slotName] = null;
645
+ filledSlots[slotName] = optional;
646
+ });
647
+ contentChildNodes.forEach(node => {
648
+ const slotName = slotMap[directiveNormalize(node.nodeName.toLowerCase())];
649
+ if (slotName) {
650
+ filledSlots[slotName] = true;
651
+ slots[slotName] = slots[slotName] || [];
652
+ slots[slotName].push(node);
653
+ } else {
654
+ $template.push(node);
655
+ }
656
+ });
657
+ Object.keys(filledSlots).forEach(slotName => {
658
+ if (!filledSlots[slotName]) {
659
+ throw new Error(`Required transclusion slot '${slotName}' on directive: ${this.name}`);
660
+ }
661
+ });
662
+ Object.keys(slots).filter(slotName => slots[slotName]).forEach(slotName => {
663
+ const nodes = slots[slotName];
664
+ slots[slotName] = (scope, cloneAttach) => {
665
+ return cloneAttach(nodes, scope);
666
+ };
667
+ });
668
+ }
669
+ attachChildrenFn.$$slots = slots;
670
+ $template.forEach(node => {
671
+ if (node.nodeType === Node.TEXT_NODE && !node.nodeValue) {
672
+ node.nodeValue = '\u200C';
673
+ }
674
+ });
675
+ }
676
+ return attachChildrenFn;
677
+ }
678
+ resolveAndBindRequiredControllers(controllerInstance) {
679
+ const directiveRequire = this.getDirectiveRequire();
680
+ const requiredControllers = this.resolveRequire(directiveRequire);
681
+ if (controllerInstance && this.directive.bindToController && isMap(directiveRequire)) {
682
+ const requiredControllersMap = requiredControllers;
683
+ Object.keys(requiredControllersMap).forEach(key => {
684
+ controllerInstance[key] = requiredControllersMap[key];
685
+ });
686
+ }
687
+ return requiredControllers;
688
+ }
689
+ compileHtml(html) {
690
+ this.element.innerHTML = html;
691
+ return this.$compile(this.element.childNodes);
692
+ }
693
+ extractChildNodes() {
694
+ const childNodes = [];
695
+ let childNode;
696
+ while (childNode = this.element.firstChild) {
697
+ childNode.remove();
698
+ childNodes.push(childNode);
699
+ }
700
+ return childNodes;
701
+ }
702
+ getDirectiveRequire() {
703
+ const require = this.directive.require || this.directive.controller && this.directive.name;
704
+ if (isMap(require)) {
705
+ Object.entries(require).forEach(([key, value]) => {
706
+ const match = value.match(REQUIRE_PREFIX_RE);
707
+ const name = value.substring(match[0].length);
708
+ if (!name) {
709
+ require[key] = match[0] + key;
710
+ }
711
+ });
712
+ }
713
+ return require;
714
+ }
715
+ resolveRequire(require) {
716
+ if (!require) {
717
+ return null;
718
+ } else if (Array.isArray(require)) {
719
+ return require.map(req => this.resolveRequire(req));
720
+ } else if (typeof require === 'object') {
721
+ const value = {};
722
+ Object.keys(require).forEach(key => value[key] = this.resolveRequire(require[key]));
723
+ return value;
724
+ } else if (typeof require === 'string') {
725
+ const match = require.match(REQUIRE_PREFIX_RE);
726
+ const inheritType = match[1] || match[3];
727
+ const name = require.substring(match[0].length);
728
+ const isOptional = !!match[2];
729
+ const searchParents = !!inheritType;
730
+ const startOnParent = inheritType === '^^';
731
+ const ctrlKey = controllerKey(name);
732
+ const elem = startOnParent ? this.$element.parent() : this.$element;
733
+ const value = searchParents ? elem.inheritedData(ctrlKey) : elem.data(ctrlKey);
734
+ if (!value && !isOptional) {
735
+ throw new Error(`Unable to find required '${require}' in upgraded directive '${this.name}'.`);
736
+ }
737
+ return value;
738
+ } else {
739
+ throw new Error(`Unrecognized 'require' syntax on upgraded directive '${this.name}': ${require}`);
740
+ }
741
+ }
742
+ }
743
+ function getOrCall(property, ...args) {
744
+ return isFunction(property) ? property(...args) : property;
745
+ }
746
+ function isMap(value) {
747
+ return value && !Array.isArray(value) && typeof value === 'object';
748
+ }
749
+ function notSupported(name, feature) {
750
+ throw new Error(`Upgraded directive '${name}' contains unsupported feature: '${feature}'.`);
751
+ }
752
+
753
+ var upgrade_helper = /*#__PURE__*/Object.freeze({
754
+ __proto__: null,
755
+ UpgradeHelper: UpgradeHelper
756
+ });
757
+
19
758
  let tempInjectorRef = null;
20
759
  function setTempInjectorRef(injector) {
21
- tempInjectorRef = injector;
760
+ tempInjectorRef = injector;
22
761
  }
23
762
  function injectorFactory() {
24
- if (!tempInjectorRef) {
25
- throw new Error('Trying to get the AngularJS injector before it being set.');
26
- }
27
- const injector = tempInjectorRef;
28
- tempInjectorRef = null; // clear the value to prevent memory leaks
29
- return injector;
763
+ if (!tempInjectorRef) {
764
+ throw new Error('Trying to get the AngularJS injector before it being set.');
765
+ }
766
+ const injector = tempInjectorRef;
767
+ tempInjectorRef = null;
768
+ return injector;
30
769
  }
31
770
  function rootScopeFactory(i) {
32
- return i.get('$rootScope');
771
+ return i.get('$rootScope');
33
772
  }
34
773
  function compileFactory(i) {
35
- return i.get('$compile');
774
+ return i.get('$compile');
36
775
  }
37
776
  function parseFactory(i) {
38
- return i.get('$parse');
39
- }
40
- const angular1Providers = [
41
- // We must use exported named functions for the ng2 factories to keep the compiler happy:
42
- // > Metadata collected contains an error that will be reported at runtime:
43
- // > Function calls are not supported.
44
- // > Consider replacing the function or lambda with a reference to an exported function
45
- { provide: '$injector', useFactory: injectorFactory, deps: [] },
46
- { provide: '$rootScope', useFactory: rootScopeFactory, deps: ['$injector'] },
47
- { provide: '$compile', useFactory: compileFactory, deps: ['$injector'] },
48
- { provide: '$parse', useFactory: parseFactory, deps: ['$injector'] },
49
- ];
777
+ return i.get('$parse');
778
+ }
779
+ const angular1Providers = [{
780
+ provide: '$injector',
781
+ useFactory: injectorFactory,
782
+ deps: []
783
+ }, {
784
+ provide: '$rootScope',
785
+ useFactory: rootScopeFactory,
786
+ deps: ['$injector']
787
+ }, {
788
+ provide: '$compile',
789
+ useFactory: compileFactory,
790
+ deps: ['$injector']
791
+ }, {
792
+ provide: '$parse',
793
+ useFactory: parseFactory,
794
+ deps: ['$injector']
795
+ }];
50
796
 
51
797
  class NgAdapterInjector {
52
- modInjector;
53
- constructor(modInjector) {
54
- this.modInjector = modInjector;
55
- }
56
- // When Angular locate a service in the component injector tree, the not found value is set to
57
- // `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR`. In such a case we should not walk up to the module
58
- // injector.
59
- // AngularJS only supports a single tree and should always check the module injector.
60
- get(token, notFoundValue) {
61
- if (notFoundValue === _NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
62
- return notFoundValue;
63
- }
64
- return this.modInjector.get(token, notFoundValue);
798
+ modInjector;
799
+ constructor(modInjector) {
800
+ this.modInjector = modInjector;
801
+ }
802
+ get(token, notFoundValue) {
803
+ if (notFoundValue === _NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
804
+ return notFoundValue;
65
805
  }
806
+ return this.modInjector.get(token, notFoundValue);
807
+ }
66
808
  }
67
809
 
68
810
  let moduleUid = 0;
69
- /**
70
- * @description
71
- *
72
- * A helper function for creating an AngularJS module that can bootstrap an Angular module
73
- * "on-demand" (possibly lazily) when a {@link downgradeComponent downgraded component} needs to be
74
- * instantiated.
75
- *
76
- * *Part of the [upgrade/static](api?query=upgrade/static) library for hybrid upgrade apps that
77
- * support AOT compilation.*
78
- *
79
- * It allows loading/bootstrapping the Angular part of a hybrid application lazily and not having to
80
- * pay the cost up-front. For example, you can have an AngularJS application that uses Angular for
81
- * specific routes and only instantiate the Angular modules if/when the user visits one of these
82
- * routes.
83
- *
84
- * The Angular module will be bootstrapped once (when requested for the first time) and the same
85
- * reference will be used from that point onwards.
86
- *
87
- * `downgradeModule()` requires either an `NgModuleFactory`, `NgModule` class or a function:
88
- * - `NgModuleFactory`: If you pass an `NgModuleFactory`, it will be used to instantiate a module
89
- * using `platformBrowser`'s {@link PlatformRef#bootstrapModuleFactory bootstrapModuleFactory()}.
90
- * NOTE: this type of the argument is deprecated. Please either provide an `NgModule` class or a
91
- * bootstrap function instead.
92
- * - `NgModule` class: If you pass an NgModule class, it will be used to instantiate a module
93
- * using `platformBrowser`'s {@link PlatformRef#bootstrapModule bootstrapModule()}.
94
- * - `Function`: If you pass a function, it is expected to return a promise resolving to an
95
- * `NgModuleRef`. The function is called with an array of extra {@link StaticProvider Providers}
96
- * that are expected to be available from the returned `NgModuleRef`'s `Injector`.
97
- *
98
- * `downgradeModule()` returns the name of the created AngularJS wrapper module. You can use it to
99
- * declare a dependency in your main AngularJS module.
100
- *
101
- * {@example upgrade/static/ts/lite/module.ts region="basic-how-to"}
102
- *
103
- * For more details on how to use `downgradeModule()` see
104
- * [Upgrading for Performance](https://angular.io/guide/upgrade).
105
- *
106
- * @usageNotes
107
- *
108
- * Apart from `UpgradeModule`, you can use the rest of the `upgrade/static` helpers as usual to
109
- * build a hybrid application. Note that the Angular pieces (e.g. downgraded services) will not be
110
- * available until the downgraded module has been bootstrapped, i.e. by instantiating a downgraded
111
- * component.
112
- *
113
- * <div class="docs-alert docs-alert-important">
114
- *
115
- * You cannot use `downgradeModule()` and `UpgradeModule` in the same hybrid application.<br />
116
- * Use one or the other.
117
- *
118
- * </div>
119
- *
120
- * ### Differences with `UpgradeModule`
121
- *
122
- * Besides their different API, there are two important internal differences between
123
- * `downgradeModule()` and `UpgradeModule` that affect the behavior of hybrid applications:
124
- *
125
- * 1. Unlike `UpgradeModule`, `downgradeModule()` does not bootstrap the main AngularJS module
126
- * inside the {@link NgZone Angular zone}.
127
- * 2. Unlike `UpgradeModule`, `downgradeModule()` does not automatically run a
128
- * [$digest()](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest) when changes are
129
- * detected in the Angular part of the application.
130
- *
131
- * What this means is that applications using `UpgradeModule` will run change detection more
132
- * frequently in order to ensure that both frameworks are properly notified about possible changes.
133
- * This will inevitably result in more change detection runs than necessary.
134
- *
135
- * `downgradeModule()`, on the other side, does not try to tie the two change detection systems as
136
- * tightly, restricting the explicit change detection runs only to cases where it knows it is
137
- * necessary (e.g. when the inputs of a downgraded component change). This improves performance,
138
- * especially in change-detection-heavy applications, but leaves it up to the developer to manually
139
- * notify each framework as needed.
140
- *
141
- * For a more detailed discussion of the differences and their implications, see
142
- * [Upgrading for Performance](https://angular.io/guide/upgrade).
143
- *
144
- * <div class="docs-alert docs-alert-helpful">
145
- *
146
- * You can manually trigger a change detection run in AngularJS using
147
- * [scope.$apply(...)](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$apply) or
148
- * [$rootScope.$digest()](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest).
149
- *
150
- * You can manually trigger a change detection run in Angular using {@link NgZone#run
151
- * ngZone.run(...)}.
152
- *
153
- * </div>
154
- *
155
- * ### Downgrading multiple modules
156
- *
157
- * It is possible to downgrade multiple modules and include them in an AngularJS application. In
158
- * that case, each downgraded module will be bootstrapped when an associated downgraded component or
159
- * injectable needs to be instantiated.
160
- *
161
- * Things to keep in mind, when downgrading multiple modules:
162
- *
163
- * - Each downgraded component/injectable needs to be explicitly associated with a downgraded
164
- * module. See `downgradeComponent()` and `downgradeInjectable()` for more details.
165
- *
166
- * - If you want some injectables to be shared among all downgraded modules, you can provide them as
167
- * `StaticProvider`s, when creating the `PlatformRef` (e.g. via `platformBrowser` or
168
- * `platformBrowserDynamic`).
169
- *
170
- * - When using {@link PlatformRef#bootstrapmodule `bootstrapModule()`} or
171
- * {@link PlatformRef#bootstrapmodulefactory `bootstrapModuleFactory()`} to bootstrap the
172
- * downgraded modules, each one is considered a "root" module. As a consequence, a new instance
173
- * will be created for every injectable provided in `"root"` (via
174
- * {@link /api/core/Injectable#providedIn providedIn}
175
- * If this is not your intention, you can have a shared module (that will act as act as the "root"
176
- * module) and create all downgraded modules using that module's injector:
177
- *
178
- * {@example upgrade/static/ts/lite-multi-shared/module.ts region="shared-root-module"}
179
- *
180
- * @publicApi
181
- */
182
811
  function downgradeModule(moduleOrBootstrapFn) {
183
- const lazyModuleName = `${UPGRADE_MODULE_NAME}.lazy${++moduleUid}`;
184
- const lazyModuleRefKey = `${LAZY_MODULE_REF}${lazyModuleName}`;
185
- const lazyInjectorKey = `${INJECTOR_KEY}${lazyModuleName}`;
186
- let bootstrapFn;
187
- if (isNgModuleType(moduleOrBootstrapFn)) {
188
- // NgModule class
189
- bootstrapFn = (extraProviders) => platformBrowser(extraProviders).bootstrapModule(moduleOrBootstrapFn);
190
- }
191
- else if (!isFunction(moduleOrBootstrapFn)) {
192
- // NgModule factory
193
- bootstrapFn = (extraProviders) => platformBrowser(extraProviders).bootstrapModuleFactory(moduleOrBootstrapFn);
194
- }
195
- else {
196
- // bootstrap function
197
- bootstrapFn = moduleOrBootstrapFn;
198
- }
199
- let injector;
200
- // Create an ng1 module to bootstrap.
201
- module_(lazyModuleName, [])
202
- .constant(UPGRADE_APP_TYPE_KEY, 3 /* ɵutil.UpgradeAppType.Lite */)
203
- .factory(INJECTOR_KEY, [lazyInjectorKey, identity])
204
- .factory(lazyInjectorKey, () => {
205
- if (!injector) {
206
- throw new Error('Trying to get the Angular injector before bootstrapping the corresponding ' +
207
- 'Angular module.');
208
- }
812
+ const lazyModuleName = `${UPGRADE_MODULE_NAME}.lazy${++moduleUid}`;
813
+ const lazyModuleRefKey = `${LAZY_MODULE_REF}${lazyModuleName}`;
814
+ const lazyInjectorKey = `${INJECTOR_KEY}${lazyModuleName}`;
815
+ let bootstrapFn;
816
+ if (isNgModuleType(moduleOrBootstrapFn)) {
817
+ bootstrapFn = extraProviders => platformBrowser(extraProviders).bootstrapModule(moduleOrBootstrapFn, {
818
+ applicationProviders: [_internalProvideZoneChangeDetection({})]
819
+ });
820
+ } else if (!isFunction(moduleOrBootstrapFn)) {
821
+ bootstrapFn = extraProviders => platformBrowser(extraProviders).bootstrapModuleFactory(moduleOrBootstrapFn, {
822
+ applicationProviders: [_internalProvideZoneChangeDetection({})]
823
+ });
824
+ } else {
825
+ bootstrapFn = moduleOrBootstrapFn;
826
+ }
827
+ let injector;
828
+ module_(lazyModuleName, []).constant(UPGRADE_APP_TYPE_KEY, 3).factory(INJECTOR_KEY, [lazyInjectorKey, identity]).factory(lazyInjectorKey, () => {
829
+ if (!injector) {
830
+ throw new Error('Trying to get the Angular injector before bootstrapping the corresponding ' + 'Angular module.');
831
+ }
832
+ return injector;
833
+ }).factory(LAZY_MODULE_REF, [lazyModuleRefKey, identity]).factory(lazyModuleRefKey, [$INJECTOR, $injector => {
834
+ setTempInjectorRef($injector);
835
+ const result = {
836
+ promise: bootstrapFn(angular1Providers).then(ref => {
837
+ injector = result.injector = new NgAdapterInjector(ref.injector);
838
+ injector.get($INJECTOR);
839
+ injector.get(PlatformRef).onDestroy(() => destroyApp($injector));
209
840
  return injector;
210
- })
211
- .factory(LAZY_MODULE_REF, [lazyModuleRefKey, identity])
212
- .factory(lazyModuleRefKey, [
213
- $INJECTOR,
214
- ($injector) => {
215
- setTempInjectorRef($injector);
216
- const result = {
217
- promise: bootstrapFn(angular1Providers).then((ref) => {
218
- injector = result.injector = new NgAdapterInjector(ref.injector);
219
- injector.get($INJECTOR);
220
- // Destroy the AngularJS app once the Angular `PlatformRef` is destroyed.
221
- // This does not happen in a typical SPA scenario, but it might be useful for
222
- // other use-cases where disposing of an Angular/AngularJS app is necessary
223
- // (such as Hot Module Replacement (HMR)).
224
- // See https://github.com/angular/angular/issues/39935.
225
- injector.get(PlatformRef).onDestroy(() => destroyApp($injector));
226
- return injector;
227
- }),
228
- };
229
- return result;
230
- },
231
- ])
232
- .config([
233
- $INJECTOR,
234
- $PROVIDE,
235
- ($injector, $provide) => {
236
- $provide.constant(DOWNGRADED_MODULE_COUNT_KEY, getDowngradedModuleCount($injector) + 1);
237
- },
238
- ]);
239
- return lazyModuleName;
841
+ })
842
+ };
843
+ return result;
844
+ }]).config([$INJECTOR, $PROVIDE, ($injector, $provide) => {
845
+ $provide.constant(DOWNGRADED_MODULE_COUNT_KEY, getDowngradedModuleCount($injector) + 1);
846
+ }]);
847
+ return lazyModuleName;
240
848
  }
241
849
  function identity(x) {
242
- return x;
850
+ return x;
243
851
  }
244
852
 
245
853
  const NOT_SUPPORTED = 'NOT_SUPPORTED';
246
854
  const INITIAL_VALUE = {
247
- __UNINITIALIZED__: true,
855
+ __UNINITIALIZED__: true
248
856
  };
249
857
  class Bindings {
250
- twoWayBoundProperties = [];
251
- twoWayBoundLastValues = [];
252
- expressionBoundProperties = [];
253
- propertyToOutputMap = {};
858
+ twoWayBoundProperties = [];
859
+ twoWayBoundLastValues = [];
860
+ expressionBoundProperties = [];
861
+ propertyToOutputMap = {};
254
862
  }
255
- /**
256
- * @description
257
- *
258
- * A helper class that allows an AngularJS component to be used from Angular.
259
- *
260
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
261
- * library for hybrid upgrade apps that support AOT compilation.*
262
- *
263
- * This helper class should be used as a base class for creating Angular directives
264
- * that wrap AngularJS components that need to be "upgraded".
265
- *
266
- * @usageNotes
267
- * ### Examples
268
- *
269
- * Let's assume that you have an AngularJS component called `ng1Hero` that needs
270
- * to be made available in Angular templates.
271
- *
272
- * {@example upgrade/static/ts/full/module.ts region="ng1-hero"}
273
- *
274
- * We must create a `Directive` that will make this AngularJS component
275
- * available inside Angular templates.
276
- *
277
- * {@example upgrade/static/ts/full/module.ts region="ng1-hero-wrapper"}
278
- *
279
- * In this example you can see that we must derive from the `UpgradeComponent`
280
- * base class but also provide an {@link Directive `@Directive`} decorator. This is
281
- * because the AOT compiler requires that this information is statically available at
282
- * compile time.
283
- *
284
- * Note that we must do the following:
285
- * * specify the directive's selector (`ng1-hero`)
286
- * * specify all inputs and outputs that the AngularJS component expects
287
- * * derive from `UpgradeComponent`
288
- * * call the base class from the constructor, passing
289
- * * the AngularJS name of the component (`ng1Hero`)
290
- * * the `ElementRef` and `Injector` for the component wrapper
291
- *
292
- * @publicApi
293
- * @extensible
294
- */
295
863
  class UpgradeComponent {
296
- helper;
297
- $element;
298
- $componentScope;
299
- directive;
300
- bindings;
301
- controllerInstance;
302
- bindingDestination;
303
- // We will be instantiating the controller in the `ngOnInit` hook, when the
304
- // first `ngOnChanges` will have been already triggered. We store the
305
- // `SimpleChanges` and "play them back" later.
306
- pendingChanges = null;
307
- unregisterDoCheckWatcher;
308
- /**
309
- * Create a new `UpgradeComponent` instance. You should not normally need to do this.
310
- * Instead you should derive a new class from this one and call the super constructor
311
- * from the base class.
312
- *
313
- * {@example upgrade/static/ts/full/module.ts region="ng1-hero-wrapper" }
314
- *
315
- * * The `name` parameter should be the name of the AngularJS directive.
316
- * * The `elementRef` and `injector` parameters should be acquired from Angular by dependency
317
- * injection into the base class constructor.
318
- */
319
- constructor(name, elementRef, injector) {
320
- this.helper = new UpgradeHelper(injector, name, elementRef);
321
- this.$element = this.helper.$element;
322
- this.directive = this.helper.directive;
323
- this.bindings = this.initializeBindings(this.directive, name);
324
- // We ask for the AngularJS scope from the Angular injector, since
325
- // we will put the new component scope onto the new injector for each component
326
- const $parentScope = injector.get($SCOPE);
327
- // QUESTION 1: Should we create an isolated scope if the scope is only true?
328
- // QUESTION 2: Should we make the scope accessible through `$element.scope()/isolateScope()`?
329
- this.$componentScope = $parentScope.$new(!!this.directive.scope);
330
- this.initializeOutputs();
331
- }
332
- /** @docs-private */
333
- ngOnInit() {
334
- // Collect contents, insert and compile template
335
- const attachChildNodes = this.helper.prepareTransclusion();
336
- const linkFn = this.helper.compileTemplate();
337
- // Instantiate controller
338
- const controllerType = this.directive.controller;
339
- const bindToController = this.directive.bindToController;
340
- let controllerInstance = controllerType
341
- ? this.helper.buildController(controllerType, this.$componentScope)
342
- : undefined;
343
- let bindingDestination;
344
- if (!bindToController) {
345
- bindingDestination = this.$componentScope;
346
- }
347
- else if (controllerType && controllerInstance) {
348
- bindingDestination = controllerInstance;
349
- }
350
- else {
351
- throw new Error(`Upgraded directive '${this.directive.name}' specifies 'bindToController' but no controller.`);
352
- }
353
- this.controllerInstance = controllerInstance;
354
- this.bindingDestination = bindingDestination;
355
- // Set up outputs
356
- this.bindOutputs(bindingDestination);
357
- // Require other controllers
358
- const requiredControllers = this.helper.resolveAndBindRequiredControllers(controllerInstance);
359
- // Hook: $onChanges
360
- if (this.pendingChanges) {
361
- this.forwardChanges(this.pendingChanges, bindingDestination);
362
- this.pendingChanges = null;
363
- }
364
- // Hook: $onInit
365
- if (this.controllerInstance && isFunction(this.controllerInstance.$onInit)) {
366
- this.controllerInstance.$onInit();
367
- }
368
- // Hook: $doCheck
369
- if (controllerInstance && isFunction(controllerInstance.$doCheck)) {
370
- const callDoCheck = () => controllerInstance?.$doCheck?.();
371
- this.unregisterDoCheckWatcher = this.$componentScope.$parent.$watch(callDoCheck);
372
- callDoCheck();
373
- }
374
- // Linking
375
- const link = this.directive.link;
376
- const preLink = typeof link == 'object' && link.pre;
377
- const postLink = typeof link == 'object' ? link.post : link;
378
- const attrs = NOT_SUPPORTED;
379
- const transcludeFn = NOT_SUPPORTED;
380
- if (preLink) {
381
- preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
382
- }
383
- linkFn(this.$componentScope, null, { parentBoundTranscludeFn: attachChildNodes });
384
- if (postLink) {
385
- postLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
386
- }
387
- // Hook: $postLink
388
- if (this.controllerInstance && isFunction(this.controllerInstance.$postLink)) {
389
- this.controllerInstance.$postLink();
390
- }
864
+ helper;
865
+ $element;
866
+ $componentScope;
867
+ directive;
868
+ bindings;
869
+ controllerInstance;
870
+ bindingDestination;
871
+ pendingChanges = null;
872
+ unregisterDoCheckWatcher;
873
+ constructor(name, elementRef, injector) {
874
+ this.helper = new UpgradeHelper(injector, name, elementRef);
875
+ this.$element = this.helper.$element;
876
+ this.directive = this.helper.directive;
877
+ this.bindings = this.initializeBindings(this.directive, name);
878
+ const $parentScope = injector.get($SCOPE);
879
+ this.$componentScope = $parentScope.$new(!!this.directive.scope);
880
+ this.initializeOutputs();
881
+ }
882
+ ngOnInit() {
883
+ const attachChildNodes = this.helper.prepareTransclusion();
884
+ const linkFn = this.helper.compileTemplate();
885
+ const controllerType = this.directive.controller;
886
+ const bindToController = this.directive.bindToController;
887
+ let controllerInstance = controllerType ? this.helper.buildController(controllerType, this.$componentScope) : undefined;
888
+ let bindingDestination;
889
+ if (!bindToController) {
890
+ bindingDestination = this.$componentScope;
891
+ } else if (controllerType && controllerInstance) {
892
+ bindingDestination = controllerInstance;
893
+ } else {
894
+ throw new Error(`Upgraded directive '${this.directive.name}' specifies 'bindToController' but no controller.`);
391
895
  }
392
- /** @docs-private */
393
- ngOnChanges(changes) {
394
- if (!this.bindingDestination) {
395
- this.pendingChanges = changes;
396
- }
397
- else {
398
- this.forwardChanges(changes, this.bindingDestination);
399
- }
896
+ this.controllerInstance = controllerInstance;
897
+ this.bindingDestination = bindingDestination;
898
+ this.bindOutputs(bindingDestination);
899
+ const requiredControllers = this.helper.resolveAndBindRequiredControllers(controllerInstance);
900
+ if (this.pendingChanges) {
901
+ this.forwardChanges(this.pendingChanges, bindingDestination);
902
+ this.pendingChanges = null;
400
903
  }
401
- /** @docs-private */
402
- ngDoCheck() {
403
- const twoWayBoundProperties = this.bindings.twoWayBoundProperties;
404
- const twoWayBoundLastValues = this.bindings.twoWayBoundLastValues;
405
- const propertyToOutputMap = this.bindings.propertyToOutputMap;
406
- twoWayBoundProperties.forEach((propName, idx) => {
407
- const newValue = this.bindingDestination?.[propName];
408
- const oldValue = twoWayBoundLastValues[idx];
409
- if (!Object.is(newValue, oldValue)) {
410
- const outputName = propertyToOutputMap[propName];
411
- const eventEmitter = this[outputName];
412
- eventEmitter.emit(newValue);
413
- twoWayBoundLastValues[idx] = newValue;
414
- }
415
- });
904
+ if (this.controllerInstance && isFunction(this.controllerInstance.$onInit)) {
905
+ this.controllerInstance.$onInit();
416
906
  }
417
- /** @docs-private */
418
- ngOnDestroy() {
419
- if (isFunction(this.unregisterDoCheckWatcher)) {
420
- this.unregisterDoCheckWatcher();
421
- }
422
- this.helper.onDestroy(this.$componentScope, this.controllerInstance);
907
+ if (controllerInstance && isFunction(controllerInstance.$doCheck)) {
908
+ const callDoCheck = () => controllerInstance?.$doCheck?.();
909
+ this.unregisterDoCheckWatcher = this.$componentScope.$parent.$watch(callDoCheck);
910
+ callDoCheck();
423
911
  }
424
- initializeBindings(directive, name) {
425
- const btcIsObject = typeof directive.bindToController === 'object';
426
- if (btcIsObject && Object.keys(directive.scope).length) {
427
- throw new Error(`Binding definitions on scope and controller at the same time is not supported.`);
428
- }
429
- const context = btcIsObject ? directive.bindToController : directive.scope;
430
- const bindings = new Bindings();
431
- if (typeof context == 'object') {
432
- Object.keys(context).forEach((propName) => {
433
- const definition = context[propName];
434
- const bindingType = definition.charAt(0);
435
- // QUESTION: What about `=*`? Ignore? Throw? Support?
436
- switch (bindingType) {
437
- case '@':
438
- case '<':
439
- // We don't need to do anything special. They will be defined as inputs on the
440
- // upgraded component facade and the change propagation will be handled by
441
- // `ngOnChanges()`.
442
- break;
443
- case '=':
444
- bindings.twoWayBoundProperties.push(propName);
445
- bindings.twoWayBoundLastValues.push(INITIAL_VALUE);
446
- bindings.propertyToOutputMap[propName] = propName + 'Change';
447
- break;
448
- case '&':
449
- bindings.expressionBoundProperties.push(propName);
450
- bindings.propertyToOutputMap[propName] = propName;
451
- break;
452
- default:
453
- let json = JSON.stringify(context);
454
- throw new Error(`Unexpected mapping '${bindingType}' in '${json}' in '${name}' directive.`);
455
- }
456
- });
457
- }
458
- return bindings;
459
- }
460
- initializeOutputs() {
461
- // Initialize the outputs for `=` and `&` bindings
462
- this.bindings.twoWayBoundProperties
463
- .concat(this.bindings.expressionBoundProperties)
464
- .forEach((propName) => {
465
- const outputName = this.bindings.propertyToOutputMap[propName];
466
- this[outputName] = new EventEmitter();
467
- });
912
+ const link = this.directive.link;
913
+ const preLink = typeof link == 'object' && link.pre;
914
+ const postLink = typeof link == 'object' ? link.post : link;
915
+ const attrs = NOT_SUPPORTED;
916
+ const transcludeFn = NOT_SUPPORTED;
917
+ if (preLink) {
918
+ preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
468
919
  }
469
- bindOutputs(bindingDestination) {
470
- // Bind `&` bindings to the corresponding outputs
471
- this.bindings.expressionBoundProperties.forEach((propName) => {
472
- const outputName = this.bindings.propertyToOutputMap[propName];
473
- const emitter = this[outputName];
474
- bindingDestination[propName] = (value) => emitter.emit(value);
475
- });
920
+ linkFn(this.$componentScope, null, {
921
+ parentBoundTranscludeFn: attachChildNodes
922
+ });
923
+ if (postLink) {
924
+ postLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
925
+ }
926
+ if (this.controllerInstance && isFunction(this.controllerInstance.$postLink)) {
927
+ this.controllerInstance.$postLink();
476
928
  }
477
- forwardChanges(changes, bindingDestination) {
478
- // Forward input changes to `bindingDestination`
479
- Object.keys(changes).forEach((propName) => (bindingDestination[propName] = changes[propName].currentValue));
480
- if (isFunction(bindingDestination.$onChanges)) {
481
- bindingDestination.$onChanges(changes);
929
+ }
930
+ ngOnChanges(changes) {
931
+ if (!this.bindingDestination) {
932
+ this.pendingChanges = changes;
933
+ } else {
934
+ this.forwardChanges(changes, this.bindingDestination);
935
+ }
936
+ }
937
+ ngDoCheck() {
938
+ const twoWayBoundProperties = this.bindings.twoWayBoundProperties;
939
+ const twoWayBoundLastValues = this.bindings.twoWayBoundLastValues;
940
+ const propertyToOutputMap = this.bindings.propertyToOutputMap;
941
+ twoWayBoundProperties.forEach((propName, idx) => {
942
+ const newValue = this.bindingDestination?.[propName];
943
+ const oldValue = twoWayBoundLastValues[idx];
944
+ if (!Object.is(newValue, oldValue)) {
945
+ const outputName = propertyToOutputMap[propName];
946
+ const eventEmitter = this[outputName];
947
+ eventEmitter.emit(newValue);
948
+ twoWayBoundLastValues[idx] = newValue;
949
+ }
950
+ });
951
+ }
952
+ ngOnDestroy() {
953
+ if (isFunction(this.unregisterDoCheckWatcher)) {
954
+ this.unregisterDoCheckWatcher();
955
+ }
956
+ this.helper.onDestroy(this.$componentScope, this.controllerInstance);
957
+ }
958
+ initializeBindings(directive, name) {
959
+ const btcIsObject = typeof directive.bindToController === 'object';
960
+ if (btcIsObject && Object.keys(directive.scope).length) {
961
+ throw new Error(`Binding definitions on scope and controller at the same time is not supported.`);
962
+ }
963
+ const context = btcIsObject ? directive.bindToController : directive.scope;
964
+ const bindings = new Bindings();
965
+ if (typeof context == 'object') {
966
+ Object.keys(context).forEach(propName => {
967
+ const definition = context[propName];
968
+ const bindingType = definition.charAt(0);
969
+ switch (bindingType) {
970
+ case '@':
971
+ case '<':
972
+ break;
973
+ case '=':
974
+ bindings.twoWayBoundProperties.push(propName);
975
+ bindings.twoWayBoundLastValues.push(INITIAL_VALUE);
976
+ bindings.propertyToOutputMap[propName] = propName + 'Change';
977
+ break;
978
+ case '&':
979
+ bindings.expressionBoundProperties.push(propName);
980
+ bindings.propertyToOutputMap[propName] = propName;
981
+ break;
982
+ default:
983
+ let json = JSON.stringify(context);
984
+ throw new Error(`Unexpected mapping '${bindingType}' in '${json}' in '${name}' directive.`);
482
985
  }
986
+ });
987
+ }
988
+ return bindings;
989
+ }
990
+ initializeOutputs() {
991
+ this.bindings.twoWayBoundProperties.concat(this.bindings.expressionBoundProperties).forEach(propName => {
992
+ const outputName = this.bindings.propertyToOutputMap[propName];
993
+ this[outputName] = new EventEmitter();
994
+ });
995
+ }
996
+ bindOutputs(bindingDestination) {
997
+ this.bindings.expressionBoundProperties.forEach(propName => {
998
+ const outputName = this.bindings.propertyToOutputMap[propName];
999
+ const emitter = this[outputName];
1000
+ bindingDestination[propName] = value => emitter.emit(value);
1001
+ });
1002
+ }
1003
+ forwardChanges(changes, bindingDestination) {
1004
+ Object.keys(changes).forEach(propName => bindingDestination[propName] = changes[propName].currentValue);
1005
+ if (isFunction(bindingDestination.$onChanges)) {
1006
+ bindingDestination.$onChanges(changes);
483
1007
  }
484
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: UpgradeComponent, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
485
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.2.0-next.2", type: UpgradeComponent, isStandalone: true, usesOnChanges: true, ngImport: i0 });
1008
+ }
1009
+ static ɵfac = i0.ɵɵngDeclareFactory({
1010
+ minVersion: "12.0.0",
1011
+ version: "21.0.0-next.10",
1012
+ ngImport: i0,
1013
+ type: UpgradeComponent,
1014
+ deps: "invalid",
1015
+ target: i0.ɵɵFactoryTarget.Directive
1016
+ });
1017
+ static ɵdir = i0.ɵɵngDeclareDirective({
1018
+ minVersion: "14.0.0",
1019
+ version: "21.0.0-next.10",
1020
+ type: UpgradeComponent,
1021
+ isStandalone: true,
1022
+ usesOnChanges: true,
1023
+ ngImport: i0
1024
+ });
486
1025
  }
487
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: UpgradeComponent, decorators: [{
488
- type: Directive
489
- }], ctorParameters: () => [{ type: undefined }, { type: i0.ElementRef }, { type: i0.Injector }] });
1026
+ i0.ɵɵngDeclareClassMetadata({
1027
+ minVersion: "12.0.0",
1028
+ version: "21.0.0-next.10",
1029
+ ngImport: i0,
1030
+ type: UpgradeComponent,
1031
+ decorators: [{
1032
+ type: Directive
1033
+ }],
1034
+ ctorParameters: () => [{
1035
+ type: undefined
1036
+ }, {
1037
+ type: i0.ElementRef
1038
+ }, {
1039
+ type: i0.Injector
1040
+ }]
1041
+ });
490
1042
 
491
- /**
492
- * @description
493
- *
494
- * An `NgModule`, which you import to provide AngularJS core services,
495
- * and has an instance method used to bootstrap the hybrid upgrade application.
496
- *
497
- * *Part of the [upgrade/static](api?query=upgrade/static)
498
- * library for hybrid upgrade apps that support AOT compilation*
499
- *
500
- * The `upgrade/static` package contains helpers that allow AngularJS and Angular components
501
- * to be used together inside a hybrid upgrade application, which supports AOT compilation.
502
- *
503
- * Specifically, the classes and functions in the `upgrade/static` module allow the following:
504
- *
505
- * 1. Creation of an Angular directive that wraps and exposes an AngularJS component so
506
- * that it can be used in an Angular template. See `UpgradeComponent`.
507
- * 2. Creation of an AngularJS directive that wraps and exposes an Angular component so
508
- * that it can be used in an AngularJS template. See `downgradeComponent`.
509
- * 3. Creation of an Angular root injector provider that wraps and exposes an AngularJS
510
- * service so that it can be injected into an Angular context. See
511
- * {@link UpgradeModule#upgrading-an-angular-1-service Upgrading an AngularJS service} below.
512
- * 4. Creation of an AngularJS service that wraps and exposes an Angular injectable
513
- * so that it can be injected into an AngularJS context. See `downgradeInjectable`.
514
- * 5. Bootstrapping of a hybrid Angular application which contains both of the frameworks
515
- * coexisting in a single application.
516
- *
517
- * @usageNotes
518
- *
519
- * ```ts
520
- * import {UpgradeModule} from '@angular/upgrade/static';
521
- * ```
522
- *
523
- * See also the {@link UpgradeModule#examples examples} below.
524
- *
525
- * ### Mental Model
526
- *
527
- * When reasoning about how a hybrid application works it is useful to have a mental model which
528
- * describes what is happening and explains what is happening at the lowest level.
529
- *
530
- * 1. There are two independent frameworks running in a single application, each framework treats
531
- * the other as a black box.
532
- * 2. Each DOM element on the page is owned exactly by one framework. Whichever framework
533
- * instantiated the element is the owner. Each framework only updates/interacts with its own
534
- * DOM elements and ignores others.
535
- * 3. AngularJS directives always execute inside the AngularJS framework codebase regardless of
536
- * where they are instantiated.
537
- * 4. Angular components always execute inside the Angular framework codebase regardless of
538
- * where they are instantiated.
539
- * 5. An AngularJS component can be "upgraded"" to an Angular component. This is achieved by
540
- * defining an Angular directive, which bootstraps the AngularJS component at its location
541
- * in the DOM. See `UpgradeComponent`.
542
- * 6. An Angular component can be "downgraded" to an AngularJS component. This is achieved by
543
- * defining an AngularJS directive, which bootstraps the Angular component at its location
544
- * in the DOM. See `downgradeComponent`.
545
- * 7. Whenever an "upgraded"/"downgraded" component is instantiated the host element is owned by
546
- * the framework doing the instantiation. The other framework then instantiates and owns the
547
- * view for that component.
548
- * 1. This implies that the component bindings will always follow the semantics of the
549
- * instantiation framework.
550
- * 2. The DOM attributes are parsed by the framework that owns the current template. So
551
- * attributes in AngularJS templates must use kebab-case, while AngularJS templates must use
552
- * camelCase.
553
- * 3. However the template binding syntax will always use the Angular style, e.g. square
554
- * brackets (`[...]`) for property binding.
555
- * 8. Angular is bootstrapped first; AngularJS is bootstrapped second. AngularJS always owns the
556
- * root component of the application.
557
- * 9. The new application is running in an Angular zone, and therefore it no longer needs calls to
558
- * `$apply()`.
559
- *
560
- * ### The `UpgradeModule` class
561
- *
562
- * This class is an `NgModule`, which you import to provide AngularJS core services,
563
- * and has an instance method used to bootstrap the hybrid upgrade application.
564
- *
565
- * * Core AngularJS services<br />
566
- * Importing this `NgModule` will add providers for the core
567
- * [AngularJS services](https://docs.angularjs.org/api/ng/service) to the root injector.
568
- *
569
- * * Bootstrap<br />
570
- * The runtime instance of this class contains a {@link UpgradeModule#bootstrap `bootstrap()`}
571
- * method, which you use to bootstrap the top level AngularJS module onto an element in the
572
- * DOM for the hybrid upgrade app.
573
- *
574
- * It also contains properties to access the {@link UpgradeModule#injector root injector}, the
575
- * bootstrap `NgZone` and the
576
- * [AngularJS $injector](https://docs.angularjs.org/api/auto/service/$injector).
577
- *
578
- * ### Examples
579
- *
580
- * Import the `UpgradeModule` into your top level Angular {@link NgModule NgModule}.
581
- *
582
- * {@example upgrade/static/ts/full/module.ts region='ng2-module'}
583
- *
584
- * Then inject `UpgradeModule` into your Angular `NgModule` and use it to bootstrap the top level
585
- * [AngularJS module](https://docs.angularjs.org/api/ng/type/angular.Module) in the
586
- * `ngDoBootstrap()` method.
587
- *
588
- * {@example upgrade/static/ts/full/module.ts region='bootstrap-ng1'}
589
- *
590
- * Finally, kick off the whole process, by bootstrapping your top level Angular `NgModule`.
591
- *
592
- * {@example upgrade/static/ts/full/module.ts region='bootstrap-ng2'}
593
- *
594
- * ### Upgrading an AngularJS service
595
- *
596
- * There is no specific API for upgrading an AngularJS service. Instead you should just follow the
597
- * following recipe:
598
- *
599
- * Let's say you have an AngularJS service:
600
- *
601
- * {@example upgrade/static/ts/full/module.ts region="ng1-text-formatter-service"}
602
- *
603
- * Then you should define an Angular provider to be included in your `NgModule` `providers`
604
- * property.
605
- *
606
- * {@example upgrade/static/ts/full/module.ts region="upgrade-ng1-service"}
607
- *
608
- * Then you can use the "upgraded" AngularJS service by injecting it into an Angular component
609
- * or service.
610
- *
611
- * {@example upgrade/static/ts/full/module.ts region="use-ng1-upgraded-service"}
612
- *
613
- * @publicApi
614
- */
615
1043
  class UpgradeModule {
616
- ngZone;
617
- platformRef;
618
- /**
619
- * The AngularJS `$injector` for the upgrade application.
620
- */
621
- $injector;
622
- /** The Angular Injector **/
623
- injector;
624
- applicationRef;
625
- constructor(
626
- /** The root `Injector` for the upgrade application. */
627
- injector,
628
- /** The bootstrap zone for the upgrade application */
629
- ngZone,
630
- /**
631
- * The owning `NgModuleRef`s `PlatformRef` instance.
632
- * This is used to tie the lifecycle of the bootstrapped AngularJS apps to that of the Angular
633
- * `PlatformRef`.
634
- */
635
- platformRef) {
636
- this.ngZone = ngZone;
637
- this.platformRef = platformRef;
638
- this.injector = new NgAdapterInjector(injector);
639
- this.applicationRef = this.injector.get(ApplicationRef);
640
- }
641
- /**
642
- * Bootstrap an AngularJS application from this NgModule
643
- * @param element the element on which to bootstrap the AngularJS application
644
- * @param [modules] the AngularJS modules to bootstrap for this application
645
- * @param [config] optional extra AngularJS bootstrap configuration
646
- * @return The value returned by
647
- * [angular.bootstrap()](https://docs.angularjs.org/api/ng/function/angular.bootstrap).
648
- */
649
- bootstrap(element$1, modules = [], config /*angular.IAngularBootstrapConfig*/) {
650
- const INIT_MODULE_NAME = UPGRADE_MODULE_NAME + '.init';
651
- // Create an ng1 module to bootstrap
652
- module_(INIT_MODULE_NAME, [])
653
- .constant(UPGRADE_APP_TYPE_KEY, 2 /* ɵutil.UpgradeAppType.Static */)
654
- .value(INJECTOR_KEY, this.injector)
655
- .factory(LAZY_MODULE_REF, [
656
- INJECTOR_KEY,
657
- (injector) => ({ injector }),
658
- ])
659
- .config([
660
- $PROVIDE,
661
- $INJECTOR,
662
- ($provide, $injector) => {
663
- if ($injector.has($$TESTABILITY)) {
664
- $provide.decorator($$TESTABILITY, [
665
- $DELEGATE,
666
- (testabilityDelegate) => {
667
- const originalWhenStable = testabilityDelegate.whenStable;
668
- const injector = this.injector;
669
- // Cannot use arrow function below because we need the context
670
- const newWhenStable = function (callback) {
671
- originalWhenStable.call(testabilityDelegate, function () {
672
- const ng2Testability = injector.get(Testability);
673
- if (ng2Testability.isStable()) {
674
- callback();
675
- }
676
- else {
677
- ng2Testability.whenStable(newWhenStable.bind(testabilityDelegate, callback));
678
- }
679
- });
680
- };
681
- testabilityDelegate.whenStable = newWhenStable;
682
- return testabilityDelegate;
683
- },
684
- ]);
685
- }
686
- if ($injector.has($INTERVAL)) {
687
- $provide.decorator($INTERVAL, [
688
- $DELEGATE,
689
- (intervalDelegate) => {
690
- // Wrap the $interval service so that setInterval is called outside NgZone,
691
- // but the callback is still invoked within it. This is so that $interval
692
- // won't block stability, which preserves the behavior from AngularJS.
693
- let wrappedInterval = (fn, delay, count, invokeApply, ...pass) => {
694
- return this.ngZone.runOutsideAngular(() => {
695
- return intervalDelegate((...args) => {
696
- // Run callback in the next VM turn - $interval calls
697
- // $rootScope.$apply, and running the callback in NgZone will
698
- // cause a '$digest already in progress' error if it's in the
699
- // same vm turn.
700
- setTimeout(() => {
701
- this.ngZone.run(() => fn(...args));
702
- });
703
- }, delay, count, invokeApply, ...pass);
704
- });
705
- };
706
- Object.keys(intervalDelegate).forEach((prop) => (wrappedInterval[prop] = intervalDelegate[prop]));
707
- // the `flush` method will be present when ngMocks is used
708
- if (intervalDelegate.hasOwnProperty('flush')) {
709
- wrappedInterval['flush'] = () => {
710
- intervalDelegate['flush']();
711
- return wrappedInterval;
712
- };
713
- }
714
- return wrappedInterval;
715
- },
716
- ]);
717
- }
718
- },
719
- ])
720
- .run([
721
- $INJECTOR,
722
- ($injector) => {
723
- this.$injector = $injector;
724
- const $rootScope = $injector.get('$rootScope');
725
- // Initialize the ng1 $injector provider
726
- setTempInjectorRef($injector);
727
- this.injector.get($INJECTOR);
728
- // Put the injector on the DOM, so that it can be "required"
729
- element(element$1).data(controllerKey(INJECTOR_KEY), this.injector);
730
- // Destroy the AngularJS app once the Angular `PlatformRef` is destroyed.
731
- // This does not happen in a typical SPA scenario, but it might be useful for
732
- // other use-cases where disposing of an Angular/AngularJS app is necessary
733
- // (such as Hot Module Replacement (HMR)).
734
- // See https://github.com/angular/angular/issues/39935.
735
- this.platformRef.onDestroy(() => destroyApp($injector));
736
- // Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
737
- // We need to do this in the next tick so that we don't prevent the bootup stabilizing
1044
+ ngZone;
1045
+ platformRef;
1046
+ $injector;
1047
+ injector;
1048
+ applicationRef;
1049
+ constructor(injector, ngZone, platformRef) {
1050
+ this.ngZone = ngZone;
1051
+ this.platformRef = platformRef;
1052
+ this.injector = new NgAdapterInjector(injector);
1053
+ this.applicationRef = this.injector.get(ApplicationRef);
1054
+ }
1055
+ bootstrap(element$1, modules = [], config) {
1056
+ const INIT_MODULE_NAME = UPGRADE_MODULE_NAME + '.init';
1057
+ module_(INIT_MODULE_NAME, []).constant(UPGRADE_APP_TYPE_KEY, 2).value(INJECTOR_KEY, this.injector).factory(LAZY_MODULE_REF, [INJECTOR_KEY, injector => ({
1058
+ injector
1059
+ })]).config([$PROVIDE, $INJECTOR, ($provide, $injector) => {
1060
+ if ($injector.has($$TESTABILITY)) {
1061
+ $provide.decorator($$TESTABILITY, [$DELEGATE, testabilityDelegate => {
1062
+ const originalWhenStable = testabilityDelegate.whenStable;
1063
+ const injector = this.injector;
1064
+ const newWhenStable = function (callback) {
1065
+ originalWhenStable.call(testabilityDelegate, function () {
1066
+ const ng2Testability = injector.get(Testability);
1067
+ if (ng2Testability.isStable()) {
1068
+ callback();
1069
+ } else {
1070
+ ng2Testability.whenStable(newWhenStable.bind(testabilityDelegate, callback));
1071
+ }
1072
+ });
1073
+ };
1074
+ testabilityDelegate.whenStable = newWhenStable;
1075
+ return testabilityDelegate;
1076
+ }]);
1077
+ }
1078
+ if ($injector.has($INTERVAL)) {
1079
+ $provide.decorator($INTERVAL, [$DELEGATE, intervalDelegate => {
1080
+ let wrappedInterval = (fn, delay, count, invokeApply, ...pass) => {
1081
+ return this.ngZone.runOutsideAngular(() => {
1082
+ return intervalDelegate((...args) => {
738
1083
  setTimeout(() => {
739
- const synchronize = () => {
740
- this.ngZone.run(() => {
741
- if ($rootScope.$$phase) {
742
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
743
- console.warn('A digest was triggered while one was already in progress. This may mean that something is triggering digests outside the Angular zone.');
744
- }
745
- $rootScope.$evalAsync();
746
- }
747
- else {
748
- $rootScope.$digest();
749
- }
750
- });
751
- };
752
- const subscription =
753
- // We _DO NOT_ usually want to have any code that does one thing for zoneless and another for ZoneJS.
754
- // This is only here because there is not enough coverage for hybrid apps anymore so we cannot
755
- // be confident that making UpgradeModule work with zoneless is a non-breaking change.
756
- this.ngZone instanceof _NoopNgZone
757
- ? this.applicationRef.afterTick.subscribe(() => synchronize())
758
- : this.ngZone.onMicrotaskEmpty.subscribe(() => synchronize());
759
- $rootScope.$on('$destroy', () => {
760
- subscription.unsubscribe();
761
- });
762
- }, 0);
763
- },
764
- ]);
765
- const upgradeModule = module_(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
766
- // Make sure resumeBootstrap() only exists if the current bootstrap is deferred
767
- const windowAngular = window['angular'];
768
- windowAngular.resumeBootstrap = undefined;
769
- // Bootstrap the AngularJS application inside our zone
770
- const returnValue = this.ngZone.run(() => bootstrap(element$1, [upgradeModule.name], config));
771
- // Patch resumeBootstrap() to run inside the ngZone
772
- if (windowAngular.resumeBootstrap) {
773
- const originalResumeBootstrap = windowAngular.resumeBootstrap;
774
- const ngZone = this.ngZone;
775
- windowAngular.resumeBootstrap = function () {
776
- let args = arguments;
777
- windowAngular.resumeBootstrap = originalResumeBootstrap;
778
- return ngZone.run(() => windowAngular.resumeBootstrap.apply(this, args));
1084
+ this.ngZone.run(() => fn(...args));
1085
+ });
1086
+ }, delay, count, invokeApply, ...pass);
1087
+ });
1088
+ };
1089
+ Object.keys(intervalDelegate).forEach(prop => wrappedInterval[prop] = intervalDelegate[prop]);
1090
+ if (intervalDelegate.hasOwnProperty('flush')) {
1091
+ wrappedInterval['flush'] = () => {
1092
+ intervalDelegate['flush']();
1093
+ return wrappedInterval;
779
1094
  };
780
- }
781
- return returnValue;
1095
+ }
1096
+ return wrappedInterval;
1097
+ }]);
1098
+ }
1099
+ }]).run([$INJECTOR, $injector => {
1100
+ this.$injector = $injector;
1101
+ const $rootScope = $injector.get('$rootScope');
1102
+ setTempInjectorRef($injector);
1103
+ this.injector.get($INJECTOR);
1104
+ element(element$1).data(controllerKey(INJECTOR_KEY), this.injector);
1105
+ this.platformRef.onDestroy(() => destroyApp($injector));
1106
+ setTimeout(() => {
1107
+ const synchronize = () => {
1108
+ this.ngZone.run(() => {
1109
+ if ($rootScope.$$phase) {
1110
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
1111
+ console.warn('A digest was triggered while one was already in progress. This may mean that something is triggering digests outside the Angular zone.');
1112
+ }
1113
+ $rootScope.$evalAsync();
1114
+ } else {
1115
+ $rootScope.$digest();
1116
+ }
1117
+ });
1118
+ };
1119
+ const subscription = this.ngZone instanceof _NoopNgZone ? this.applicationRef.afterTick.subscribe(() => synchronize()) : this.ngZone.onMicrotaskEmpty.subscribe(() => synchronize());
1120
+ $rootScope.$on('$destroy', () => {
1121
+ subscription.unsubscribe();
1122
+ });
1123
+ }, 0);
1124
+ }]);
1125
+ const upgradeModule = module_(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
1126
+ const windowAngular = window['angular'];
1127
+ windowAngular.resumeBootstrap = undefined;
1128
+ const returnValue = this.ngZone.run(() => bootstrap(element$1, [upgradeModule.name], config));
1129
+ if (windowAngular.resumeBootstrap) {
1130
+ const originalResumeBootstrap = windowAngular.resumeBootstrap;
1131
+ const ngZone = this.ngZone;
1132
+ windowAngular.resumeBootstrap = function () {
1133
+ let args = arguments;
1134
+ windowAngular.resumeBootstrap = originalResumeBootstrap;
1135
+ return ngZone.run(() => windowAngular.resumeBootstrap.apply(this, args));
1136
+ };
782
1137
  }
783
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: UpgradeModule, deps: [{ token: i0.Injector }, { token: i0.NgZone }, { token: i0.PlatformRef }], target: i0.ɵɵFactoryTarget.NgModule });
784
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.2.0-next.2", ngImport: i0, type: UpgradeModule });
785
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: UpgradeModule, providers: [angular1Providers] });
1138
+ return returnValue;
1139
+ }
1140
+ static ɵfac = i0.ɵɵngDeclareFactory({
1141
+ minVersion: "12.0.0",
1142
+ version: "21.0.0-next.10",
1143
+ ngImport: i0,
1144
+ type: UpgradeModule,
1145
+ deps: [{
1146
+ token: i0.Injector
1147
+ }, {
1148
+ token: i0.NgZone
1149
+ }, {
1150
+ token: i0.PlatformRef
1151
+ }],
1152
+ target: i0.ɵɵFactoryTarget.NgModule
1153
+ });
1154
+ static ɵmod = i0.ɵɵngDeclareNgModule({
1155
+ minVersion: "14.0.0",
1156
+ version: "21.0.0-next.10",
1157
+ ngImport: i0,
1158
+ type: UpgradeModule
1159
+ });
1160
+ static ɵinj = i0.ɵɵngDeclareInjector({
1161
+ minVersion: "12.0.0",
1162
+ version: "21.0.0-next.10",
1163
+ ngImport: i0,
1164
+ type: UpgradeModule,
1165
+ providers: [angular1Providers, _internalProvideZoneChangeDetection({})]
1166
+ });
786
1167
  }
787
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: UpgradeModule, decorators: [{
788
- type: NgModule,
789
- args: [{ providers: [angular1Providers] }]
790
- }], ctorParameters: () => [{ type: i0.Injector }, { type: i0.NgZone }, { type: i0.PlatformRef }] });
1168
+ i0.ɵɵngDeclareClassMetadata({
1169
+ minVersion: "12.0.0",
1170
+ version: "21.0.0-next.10",
1171
+ ngImport: i0,
1172
+ type: UpgradeModule,
1173
+ decorators: [{
1174
+ type: NgModule,
1175
+ args: [{
1176
+ providers: [angular1Providers, _internalProvideZoneChangeDetection({})]
1177
+ }]
1178
+ }],
1179
+ ctorParameters: () => [{
1180
+ type: i0.Injector
1181
+ }, {
1182
+ type: i0.NgZone
1183
+ }, {
1184
+ type: i0.PlatformRef
1185
+ }]
1186
+ });
791
1187
 
792
- export { UpgradeComponent, UpgradeModule, downgradeModule };
1188
+ export { UpgradeComponent, UpgradeModule, downgradeComponent, downgradeInjectable, downgradeModule, upgrade_helper as ɵupgradeHelper, util as ɵutil };
793
1189
  //# sourceMappingURL=static.mjs.map