@angular/upgrade 13.0.0-next.8 → 13.0.0-rc.2

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.
Files changed (73) hide show
  1. package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  2. package/{esm2015/public_api.js → esm2020/public_api.mjs} +0 -0
  3. package/{esm2015/src/common/src/angular1.js → esm2020/src/common/src/angular1.mjs} +2 -2
  4. package/{esm2015/src/common/src/component_info.js → esm2020/src/common/src/component_info.mjs} +0 -0
  5. package/{esm2015/src/common/src/constants.js → esm2020/src/common/src/constants.mjs} +0 -0
  6. package/{esm2015/src/common/src/downgrade_component.js → esm2020/src/common/src/downgrade_component.mjs} +0 -0
  7. package/{esm2015/src/common/src/downgrade_component_adapter.js → esm2020/src/common/src/downgrade_component_adapter.mjs} +0 -0
  8. package/{esm2015/src/common/src/downgrade_injectable.js → esm2020/src/common/src/downgrade_injectable.mjs} +0 -0
  9. package/{esm2015/src/common/src/promise_util.js → esm2020/src/common/src/promise_util.mjs} +0 -0
  10. package/{esm2015/src/common/src/upgrade_helper.js → esm2020/src/common/src/upgrade_helper.mjs} +0 -0
  11. package/{esm2015/src/common/src/util.js → esm2020/src/common/src/util.mjs} +0 -0
  12. package/{esm2015/src/common/src/version.js → esm2020/src/common/src/version.mjs} +1 -1
  13. package/esm2020/src/dynamic/src/upgrade_adapter.mjs +683 -0
  14. package/esm2020/src/dynamic/src/upgrade_ng1_adapter.mjs +223 -0
  15. package/{esm2015/static/index.js → esm2020/static/index.mjs} +0 -0
  16. package/{esm2015/static/public_api.js → esm2020/static/public_api.mjs} +0 -0
  17. package/{esm2015/static/src/angular1_providers.js → esm2020/static/src/angular1_providers.mjs} +0 -0
  18. package/{esm2015/static/src/downgrade_module.js → esm2020/static/src/downgrade_module.mjs} +0 -0
  19. package/esm2020/static/src/upgrade_component.mjs +240 -0
  20. package/esm2020/static/src/upgrade_module.mjs +291 -0
  21. package/{esm2015/static/src/util.js → esm2020/static/src/util.mjs} +0 -0
  22. package/esm2020/static/static.mjs +5 -0
  23. package/{esm2015/static/testing/index.js → esm2020/static/testing/index.mjs} +0 -0
  24. package/{esm2015/static/testing/public_api.js → esm2020/static/testing/public_api.mjs} +0 -0
  25. package/esm2020/static/testing/src/create_angular_testing_module.mjs +101 -0
  26. package/{esm2015/static/testing/src/create_angularjs_testing_module.js → esm2020/static/testing/src/create_angularjs_testing_module.mjs} +0 -0
  27. package/esm2020/static/testing/testing.mjs +5 -0
  28. package/{esm2015/upgrade.js → esm2020/upgrade.mjs} +0 -0
  29. package/fesm2015/static/{testing.js → testing.mjs} +16 -14
  30. package/fesm2015/static/testing.mjs.map +1 -0
  31. package/fesm2015/{static.js → static.mjs} +23 -26
  32. package/fesm2015/static.mjs.map +1 -0
  33. package/fesm2015/upgrade.mjs +2061 -0
  34. package/fesm2015/upgrade.mjs.map +1 -0
  35. package/fesm2020/static/testing.mjs +325 -0
  36. package/fesm2020/static/testing.mjs.map +1 -0
  37. package/fesm2020/static.mjs +1931 -0
  38. package/fesm2020/static.mjs.map +1 -0
  39. package/{fesm2015/upgrade.js → fesm2020/upgrade.mjs} +32 -48
  40. package/fesm2020/upgrade.mjs.map +1 -0
  41. package/package.json +41 -11
  42. package/static/package.json +5 -5
  43. package/static/static.d.ts +7 -20
  44. package/static/testing/package.json +5 -5
  45. package/static/testing/testing.d.ts +1 -133
  46. package/upgrade.d.ts +1 -1
  47. package/bundles/upgrade-static-testing.umd.js +0 -335
  48. package/bundles/upgrade-static-testing.umd.js.map +0 -1
  49. package/bundles/upgrade-static.umd.js +0 -2303
  50. package/bundles/upgrade-static.umd.js.map +0 -1
  51. package/bundles/upgrade.umd.js +0 -2423
  52. package/bundles/upgrade.umd.js.map +0 -1
  53. package/esm2015/src/common/common.externs.js +0 -0
  54. package/esm2015/src/dynamic/src/upgrade_adapter.js +0 -682
  55. package/esm2015/src/dynamic/src/upgrade_ng1_adapter.js +0 -231
  56. package/esm2015/static/src/upgrade_component.js +0 -242
  57. package/esm2015/static/src/upgrade_module.js +0 -291
  58. package/esm2015/static/static.externs.js +0 -6
  59. package/esm2015/static/static.js +0 -6
  60. package/esm2015/static/testing/src/create_angular_testing_module.js +0 -99
  61. package/esm2015/static/testing/testing.externs.js +0 -6
  62. package/esm2015/static/testing/testing.js +0 -7
  63. package/esm2015/upgrade.externs.js +0 -6
  64. package/fesm2015/static/testing.js.map +0 -1
  65. package/fesm2015/static.js.map +0 -1
  66. package/fesm2015/upgrade.js.map +0 -1
  67. package/static/static.metadata.json +0 -1
  68. package/static/testing/testing.metadata.json +0 -1
  69. package/static/testing.d.ts +0 -7
  70. package/static/testing.metadata.json +0 -1
  71. package/static.d.ts +0 -7
  72. package/static.metadata.json +0 -1
  73. package/upgrade.metadata.json +0 -1
@@ -1,2303 +0,0 @@
1
- /**
2
- * @license Angular v13.0.0-next.8
3
- * (c) 2010-2021 Google LLC. https://angular.io/
4
- * License: MIT
5
- */
6
-
7
- (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/platform-browser')) :
9
- typeof define === 'function' && define.amd ? define('@angular/upgrade/static', ['exports', '@angular/core', '@angular/platform-browser'], factory) :
10
- (global = global || self, factory((global.ng = global.ng || {}, global.ng.upgrade = global.ng.upgrade || {}, global.ng.upgrade.static = {}), global.ng.core, global.ng.platformBrowser));
11
- }(this, (function (exports, core, platformBrowser) { 'use strict';
12
-
13
- /**
14
- * @license
15
- * Copyright Google LLC All Rights Reserved.
16
- *
17
- * Use of this source code is governed by an MIT-style license that can be
18
- * found in the LICENSE file at https://angular.io/license
19
- */
20
- function noNg() {
21
- throw new Error('AngularJS v1.x is not loaded!');
22
- }
23
- var noNgElement = (function () { return noNg(); });
24
- noNgElement.cleanData = noNg;
25
- var angular = {
26
- bootstrap: noNg,
27
- module: noNg,
28
- element: noNgElement,
29
- injector: noNg,
30
- version: undefined,
31
- resumeBootstrap: noNg,
32
- getTestability: noNg
33
- };
34
- try {
35
- if (window.hasOwnProperty('angular')) {
36
- angular = window.angular;
37
- }
38
- }
39
- catch (_a) {
40
- // ignore in CJS mode.
41
- }
42
- /**
43
- * @deprecated Use `setAngularJSGlobal` instead.
44
- *
45
- * @publicApi
46
- */
47
- function setAngularLib(ng) {
48
- setAngularJSGlobal(ng);
49
- }
50
- /**
51
- * @deprecated Use `getAngularJSGlobal` instead.
52
- *
53
- * @publicApi
54
- */
55
- function getAngularLib() {
56
- return getAngularJSGlobal();
57
- }
58
- /**
59
- * Resets the AngularJS global.
60
- *
61
- * Used when AngularJS is loaded lazily, and not available on `window`.
62
- *
63
- * @publicApi
64
- */
65
- function setAngularJSGlobal(ng) {
66
- angular = ng;
67
- }
68
- /**
69
- * Returns the current AngularJS global.
70
- *
71
- * @publicApi
72
- */
73
- function getAngularJSGlobal() {
74
- return angular;
75
- }
76
- var bootstrap = function (e, modules, config) { return angular.bootstrap(e, modules, config); };
77
- // Do not declare as `module` to avoid webpack bug
78
- // (see https://github.com/angular/angular/issues/30050).
79
- var module_ = function (prefix, dependencies) { return angular.module(prefix, dependencies); };
80
- var element = (function (e) { return angular.element(e); });
81
- element.cleanData = function (nodes) { return angular.element.cleanData(nodes); };
82
- var injector = function (modules, strictDi) { return angular.injector(modules, strictDi); };
83
- var resumeBootstrap = function () { return angular.resumeBootstrap(); };
84
- var getTestability = function (e) { return angular.getTestability(e); };
85
-
86
- /*! *****************************************************************************
87
- Copyright (c) Microsoft Corporation.
88
-
89
- Permission to use, copy, modify, and/or distribute this software for any
90
- purpose with or without fee is hereby granted.
91
-
92
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
93
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
94
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
95
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
96
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
97
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
98
- PERFORMANCE OF THIS SOFTWARE.
99
- ***************************************************************************** */
100
- /* global Reflect, Promise */
101
- var extendStatics = function (d, b) {
102
- extendStatics = Object.setPrototypeOf ||
103
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
104
- function (d, b) { for (var p in b)
105
- if (Object.prototype.hasOwnProperty.call(b, p))
106
- d[p] = b[p]; };
107
- return extendStatics(d, b);
108
- };
109
- function __extends(d, b) {
110
- if (typeof b !== "function" && b !== null)
111
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
112
- extendStatics(d, b);
113
- function __() { this.constructor = d; }
114
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
115
- }
116
- var __assign = function () {
117
- __assign = Object.assign || function __assign(t) {
118
- for (var s, i = 1, n = arguments.length; i < n; i++) {
119
- s = arguments[i];
120
- for (var p in s)
121
- if (Object.prototype.hasOwnProperty.call(s, p))
122
- t[p] = s[p];
123
- }
124
- return t;
125
- };
126
- return __assign.apply(this, arguments);
127
- };
128
- function __rest(s, e) {
129
- var t = {};
130
- for (var p in s)
131
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
132
- t[p] = s[p];
133
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
134
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
135
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
136
- t[p[i]] = s[p[i]];
137
- }
138
- return t;
139
- }
140
- function __decorate(decorators, target, key, desc) {
141
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
142
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
143
- r = Reflect.decorate(decorators, target, key, desc);
144
- else
145
- for (var i = decorators.length - 1; i >= 0; i--)
146
- if (d = decorators[i])
147
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
148
- return c > 3 && r && Object.defineProperty(target, key, r), r;
149
- }
150
- function __param(paramIndex, decorator) {
151
- return function (target, key) { decorator(target, key, paramIndex); };
152
- }
153
- function __metadata(metadataKey, metadataValue) {
154
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
155
- return Reflect.metadata(metadataKey, metadataValue);
156
- }
157
- function __awaiter(thisArg, _arguments, P, generator) {
158
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
159
- return new (P || (P = Promise))(function (resolve, reject) {
160
- function fulfilled(value) { try {
161
- step(generator.next(value));
162
- }
163
- catch (e) {
164
- reject(e);
165
- } }
166
- function rejected(value) { try {
167
- step(generator["throw"](value));
168
- }
169
- catch (e) {
170
- reject(e);
171
- } }
172
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
173
- step((generator = generator.apply(thisArg, _arguments || [])).next());
174
- });
175
- }
176
- function __generator(thisArg, body) {
177
- var _ = { label: 0, sent: function () { if (t[0] & 1)
178
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
179
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
180
- function verb(n) { return function (v) { return step([n, v]); }; }
181
- function step(op) {
182
- if (f)
183
- throw new TypeError("Generator is already executing.");
184
- while (_)
185
- try {
186
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
187
- return t;
188
- if (y = 0, t)
189
- op = [op[0] & 2, t.value];
190
- switch (op[0]) {
191
- case 0:
192
- case 1:
193
- t = op;
194
- break;
195
- case 4:
196
- _.label++;
197
- return { value: op[1], done: false };
198
- case 5:
199
- _.label++;
200
- y = op[1];
201
- op = [0];
202
- continue;
203
- case 7:
204
- op = _.ops.pop();
205
- _.trys.pop();
206
- continue;
207
- default:
208
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
209
- _ = 0;
210
- continue;
211
- }
212
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
213
- _.label = op[1];
214
- break;
215
- }
216
- if (op[0] === 6 && _.label < t[1]) {
217
- _.label = t[1];
218
- t = op;
219
- break;
220
- }
221
- if (t && _.label < t[2]) {
222
- _.label = t[2];
223
- _.ops.push(op);
224
- break;
225
- }
226
- if (t[2])
227
- _.ops.pop();
228
- _.trys.pop();
229
- continue;
230
- }
231
- op = body.call(thisArg, _);
232
- }
233
- catch (e) {
234
- op = [6, e];
235
- y = 0;
236
- }
237
- finally {
238
- f = t = 0;
239
- }
240
- if (op[0] & 5)
241
- throw op[1];
242
- return { value: op[0] ? op[1] : void 0, done: true };
243
- }
244
- }
245
- var __createBinding = Object.create ? (function (o, m, k, k2) {
246
- if (k2 === undefined)
247
- k2 = k;
248
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
249
- }) : (function (o, m, k, k2) {
250
- if (k2 === undefined)
251
- k2 = k;
252
- o[k2] = m[k];
253
- });
254
- function __exportStar(m, o) {
255
- for (var p in m)
256
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
257
- __createBinding(o, m, p);
258
- }
259
- function __values(o) {
260
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
261
- if (m)
262
- return m.call(o);
263
- if (o && typeof o.length === "number")
264
- return {
265
- next: function () {
266
- if (o && i >= o.length)
267
- o = void 0;
268
- return { value: o && o[i++], done: !o };
269
- }
270
- };
271
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
272
- }
273
- function __read(o, n) {
274
- var m = typeof Symbol === "function" && o[Symbol.iterator];
275
- if (!m)
276
- return o;
277
- var i = m.call(o), r, ar = [], e;
278
- try {
279
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
280
- ar.push(r.value);
281
- }
282
- catch (error) {
283
- e = { error: error };
284
- }
285
- finally {
286
- try {
287
- if (r && !r.done && (m = i["return"]))
288
- m.call(i);
289
- }
290
- finally {
291
- if (e)
292
- throw e.error;
293
- }
294
- }
295
- return ar;
296
- }
297
- /** @deprecated */
298
- function __spread() {
299
- for (var ar = [], i = 0; i < arguments.length; i++)
300
- ar = ar.concat(__read(arguments[i]));
301
- return ar;
302
- }
303
- /** @deprecated */
304
- function __spreadArrays() {
305
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
306
- s += arguments[i].length;
307
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
308
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
309
- r[k] = a[j];
310
- return r;
311
- }
312
- function __spreadArray(to, from, pack) {
313
- if (pack || arguments.length === 2)
314
- for (var i = 0, l = from.length, ar; i < l; i++) {
315
- if (ar || !(i in from)) {
316
- if (!ar)
317
- ar = Array.prototype.slice.call(from, 0, i);
318
- ar[i] = from[i];
319
- }
320
- }
321
- return to.concat(ar || Array.prototype.slice.call(from));
322
- }
323
- function __await(v) {
324
- return this instanceof __await ? (this.v = v, this) : new __await(v);
325
- }
326
- function __asyncGenerator(thisArg, _arguments, generator) {
327
- if (!Symbol.asyncIterator)
328
- throw new TypeError("Symbol.asyncIterator is not defined.");
329
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
330
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
331
- function verb(n) { if (g[n])
332
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
333
- function resume(n, v) { try {
334
- step(g[n](v));
335
- }
336
- catch (e) {
337
- settle(q[0][3], e);
338
- } }
339
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
340
- function fulfill(value) { resume("next", value); }
341
- function reject(value) { resume("throw", value); }
342
- function settle(f, v) { if (f(v), q.shift(), q.length)
343
- resume(q[0][0], q[0][1]); }
344
- }
345
- function __asyncDelegator(o) {
346
- var i, p;
347
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
348
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
349
- }
350
- function __asyncValues(o) {
351
- if (!Symbol.asyncIterator)
352
- throw new TypeError("Symbol.asyncIterator is not defined.");
353
- var m = o[Symbol.asyncIterator], i;
354
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
355
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
356
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
357
- }
358
- function __makeTemplateObject(cooked, raw) {
359
- if (Object.defineProperty) {
360
- Object.defineProperty(cooked, "raw", { value: raw });
361
- }
362
- else {
363
- cooked.raw = raw;
364
- }
365
- return cooked;
366
- }
367
- ;
368
- var __setModuleDefault = Object.create ? (function (o, v) {
369
- Object.defineProperty(o, "default", { enumerable: true, value: v });
370
- }) : function (o, v) {
371
- o["default"] = v;
372
- };
373
- function __importStar(mod) {
374
- if (mod && mod.__esModule)
375
- return mod;
376
- var result = {};
377
- if (mod != null)
378
- for (var k in mod)
379
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
380
- __createBinding(result, mod, k);
381
- __setModuleDefault(result, mod);
382
- return result;
383
- }
384
- function __importDefault(mod) {
385
- return (mod && mod.__esModule) ? mod : { default: mod };
386
- }
387
- function __classPrivateFieldGet(receiver, state, kind, f) {
388
- if (kind === "a" && !f)
389
- throw new TypeError("Private accessor was defined without a getter");
390
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
391
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
392
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
393
- }
394
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
395
- if (kind === "m")
396
- throw new TypeError("Private method is not writable");
397
- if (kind === "a" && !f)
398
- throw new TypeError("Private accessor was defined without a setter");
399
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
400
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
401
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
402
- }
403
-
404
- /**
405
- * @license
406
- * Copyright Google LLC All Rights Reserved.
407
- *
408
- * Use of this source code is governed by an MIT-style license that can be
409
- * found in the LICENSE file at https://angular.io/license
410
- */
411
- var $COMPILE = '$compile';
412
- var $CONTROLLER = '$controller';
413
- var $DELEGATE = '$delegate';
414
- var $EXCEPTION_HANDLER = '$exceptionHandler';
415
- var $HTTP_BACKEND = '$httpBackend';
416
- var $INJECTOR = '$injector';
417
- var $INTERVAL = '$interval';
418
- var $PARSE = '$parse';
419
- var $PROVIDE = '$provide';
420
- var $ROOT_ELEMENT = '$rootElement';
421
- var $ROOT_SCOPE = '$rootScope';
422
- var $SCOPE = '$scope';
423
- var $TEMPLATE_CACHE = '$templateCache';
424
- var $TEMPLATE_REQUEST = '$templateRequest';
425
- var $$TESTABILITY = '$$testability';
426
- var COMPILER_KEY = '$$angularCompiler';
427
- var DOWNGRADED_MODULE_COUNT_KEY = '$$angularDowngradedModuleCount';
428
- var GROUP_PROJECTABLE_NODES_KEY = '$$angularGroupProjectableNodes';
429
- var INJECTOR_KEY = '$$angularInjector';
430
- var LAZY_MODULE_REF = '$$angularLazyModuleRef';
431
- var NG_ZONE_KEY = '$$angularNgZone';
432
- var UPGRADE_APP_TYPE_KEY = '$$angularUpgradeAppType';
433
- var REQUIRE_INJECTOR = '?^^' + INJECTOR_KEY;
434
- var REQUIRE_NG_MODEL = '?ngModel';
435
- var UPGRADE_MODULE_NAME = '$$UpgradeModule';
436
-
437
- /**
438
- * @license
439
- * Copyright Google LLC All Rights Reserved.
440
- *
441
- * Use of this source code is governed by an MIT-style license that can be
442
- * found in the LICENSE file at https://angular.io/license
443
- */
444
- /**
445
- * A `PropertyBinding` represents a mapping between a property name
446
- * and an attribute name. It is parsed from a string of the form
447
- * `"prop: attr"`; or simply `"propAndAttr" where the property
448
- * and attribute have the same identifier.
449
- */
450
- var PropertyBinding = /** @class */ (function () {
451
- function PropertyBinding(prop, attr) {
452
- this.prop = prop;
453
- this.attr = attr;
454
- this.parseBinding();
455
- }
456
- PropertyBinding.prototype.parseBinding = function () {
457
- this.bracketAttr = "[" + this.attr + "]";
458
- this.parenAttr = "(" + this.attr + ")";
459
- this.bracketParenAttr = "[(" + this.attr + ")]";
460
- var capitalAttr = this.attr.charAt(0).toUpperCase() + this.attr.substr(1);
461
- this.onAttr = "on" + capitalAttr;
462
- this.bindAttr = "bind" + capitalAttr;
463
- this.bindonAttr = "bindon" + capitalAttr;
464
- };
465
- return PropertyBinding;
466
- }());
467
-
468
- /**
469
- * @license
470
- * Copyright Google LLC All Rights Reserved.
471
- *
472
- * Use of this source code is governed by an MIT-style license that can be
473
- * found in the LICENSE file at https://angular.io/license
474
- */
475
- var DIRECTIVE_PREFIX_REGEXP = /^(?:x|data)[:\-_]/i;
476
- var DIRECTIVE_SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
477
- function onError(e) {
478
- // TODO: (misko): We seem to not have a stack trace here!
479
- if (console.error) {
480
- console.error(e, e.stack);
481
- }
482
- else {
483
- // tslint:disable-next-line:no-console
484
- console.log(e, e.stack);
485
- }
486
- throw e;
487
- }
488
- /**
489
- * Clean the jqLite/jQuery data on the element and all its descendants.
490
- * Equivalent to how jqLite/jQuery invoke `cleanData()` on an Element when removed:
491
- * https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/jqLite.js#L349-L355
492
- * https://github.com/jquery/jquery/blob/6984d1747623dbc5e87fd6c261a5b6b1628c107c/src/manipulation.js#L182
493
- *
494
- * NOTE:
495
- * `cleanData()` will also invoke the AngularJS `$destroy` DOM event on the element:
496
- * https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/Angular.js#L1932-L1945
497
- *
498
- * @param node The DOM node whose data needs to be cleaned.
499
- */
500
- function cleanData(node) {
501
- element.cleanData([node]);
502
- if (isParentNode(node)) {
503
- element.cleanData(node.querySelectorAll('*'));
504
- }
505
- }
506
- function controllerKey(name) {
507
- return '$' + name + 'Controller';
508
- }
509
- /**
510
- * Destroy an AngularJS app given the app `$injector`.
511
- *
512
- * NOTE: Destroying an app is not officially supported by AngularJS, but try to do our best by
513
- * destroying `$rootScope` and clean the jqLite/jQuery data on `$rootElement` and all
514
- * descendants.
515
- *
516
- * @param $injector The `$injector` of the AngularJS app to destroy.
517
- */
518
- function destroyApp($injector) {
519
- var $rootElement = $injector.get($ROOT_ELEMENT);
520
- var $rootScope = $injector.get($ROOT_SCOPE);
521
- $rootScope.$destroy();
522
- cleanData($rootElement[0]);
523
- }
524
- function directiveNormalize(name) {
525
- return name.replace(DIRECTIVE_PREFIX_REGEXP, '')
526
- .replace(DIRECTIVE_SPECIAL_CHARS_REGEXP, function (_, letter) { return letter.toUpperCase(); });
527
- }
528
- function getTypeName(type) {
529
- // Return the name of the type or the first line of its stringified version.
530
- return type.overriddenName || type.name || type.toString().split('\n')[0];
531
- }
532
- function getDowngradedModuleCount($injector) {
533
- return $injector.has(DOWNGRADED_MODULE_COUNT_KEY) ? $injector.get(DOWNGRADED_MODULE_COUNT_KEY) :
534
- 0;
535
- }
536
- function getUpgradeAppType($injector) {
537
- return $injector.has(UPGRADE_APP_TYPE_KEY) ? $injector.get(UPGRADE_APP_TYPE_KEY) :
538
- 0 /* None */;
539
- }
540
- function isFunction(value) {
541
- return typeof value === 'function';
542
- }
543
- function isParentNode(node) {
544
- return isFunction(node.querySelectorAll);
545
- }
546
- function validateInjectionKey($injector, downgradedModule, injectionKey, attemptedAction) {
547
- var upgradeAppType = getUpgradeAppType($injector);
548
- var downgradedModuleCount = getDowngradedModuleCount($injector);
549
- // Check for common errors.
550
- switch (upgradeAppType) {
551
- case 1 /* Dynamic */:
552
- case 2 /* Static */:
553
- if (downgradedModule) {
554
- throw new Error("Error while " + attemptedAction + ": 'downgradedModule' unexpectedly specified.\n" +
555
- 'You should not specify a value for \'downgradedModule\', unless you are downgrading ' +
556
- 'more than one Angular module (via \'downgradeModule()\').');
557
- }
558
- break;
559
- case 3 /* Lite */:
560
- if (!downgradedModule && (downgradedModuleCount >= 2)) {
561
- throw new Error("Error while " + attemptedAction + ": 'downgradedModule' not specified.\n" +
562
- 'This application contains more than one downgraded Angular module, thus you need to ' +
563
- 'always specify \'downgradedModule\' when downgrading components and injectables.');
564
- }
565
- if (!$injector.has(injectionKey)) {
566
- throw new Error("Error while " + attemptedAction + ": Unable to find the specified downgraded module.\n" +
567
- 'Did you forget to downgrade an Angular module or include it in the AngularJS ' +
568
- 'application?');
569
- }
570
- break;
571
- default:
572
- throw new Error("Error while " + attemptedAction + ": Not a valid '@angular/upgrade' application.\n" +
573
- 'Did you forget to downgrade an Angular module or include it in the AngularJS ' +
574
- 'application?');
575
- }
576
- }
577
- var Deferred = /** @class */ (function () {
578
- function Deferred() {
579
- var _this = this;
580
- this.promise = new Promise(function (res, rej) {
581
- _this.resolve = res;
582
- _this.reject = rej;
583
- });
584
- }
585
- return Deferred;
586
- }());
587
- /**
588
- * @return Whether the passed-in component implements the subset of the
589
- * `ControlValueAccessor` interface needed for AngularJS `ng-model`
590
- * compatibility.
591
- */
592
- function supportsNgModel(component) {
593
- return typeof component.writeValue === 'function' &&
594
- typeof component.registerOnChange === 'function';
595
- }
596
- /**
597
- * Glue the AngularJS `NgModelController` (if it exists) to the component
598
- * (if it implements the needed subset of the `ControlValueAccessor` interface).
599
- */
600
- function hookupNgModel(ngModel, component) {
601
- if (ngModel && supportsNgModel(component)) {
602
- ngModel.$render = function () {
603
- component.writeValue(ngModel.$viewValue);
604
- };
605
- component.registerOnChange(ngModel.$setViewValue.bind(ngModel));
606
- if (typeof component.registerOnTouched === 'function') {
607
- component.registerOnTouched(ngModel.$setTouched.bind(ngModel));
608
- }
609
- }
610
- }
611
- /**
612
- * Test two values for strict equality, accounting for the fact that `NaN !== NaN`.
613
- */
614
- function strictEquals(val1, val2) {
615
- return val1 === val2 || (val1 !== val1 && val2 !== val2);
616
- }
617
-
618
- /**
619
- * @license
620
- * Copyright Google LLC All Rights Reserved.
621
- *
622
- * Use of this source code is governed by an MIT-style license that can be
623
- * found in the LICENSE file at https://angular.io/license
624
- */
625
- var INITIAL_VALUE = {
626
- __UNINITIALIZED__: true
627
- };
628
- var DowngradeComponentAdapter = /** @class */ (function () {
629
- function DowngradeComponentAdapter(element, attrs, scope, ngModel, parentInjector, $compile, $parse, componentFactory, wrapCallback) {
630
- this.element = element;
631
- this.attrs = attrs;
632
- this.scope = scope;
633
- this.ngModel = ngModel;
634
- this.parentInjector = parentInjector;
635
- this.$compile = $compile;
636
- this.$parse = $parse;
637
- this.componentFactory = componentFactory;
638
- this.wrapCallback = wrapCallback;
639
- this.implementsOnChanges = false;
640
- this.inputChangeCount = 0;
641
- this.inputChanges = {};
642
- this.componentScope = scope.$new();
643
- }
644
- DowngradeComponentAdapter.prototype.compileContents = function () {
645
- var _this = this;
646
- var compiledProjectableNodes = [];
647
- var projectableNodes = this.groupProjectableNodes();
648
- var linkFns = projectableNodes.map(function (nodes) { return _this.$compile(nodes); });
649
- this.element.empty();
650
- linkFns.forEach(function (linkFn) {
651
- linkFn(_this.scope, function (clone) {
652
- compiledProjectableNodes.push(clone);
653
- _this.element.append(clone);
654
- });
655
- });
656
- return compiledProjectableNodes;
657
- };
658
- DowngradeComponentAdapter.prototype.createComponent = function (projectableNodes) {
659
- var providers = [{ provide: $SCOPE, useValue: this.componentScope }];
660
- var childInjector = core.Injector.create({ providers: providers, parent: this.parentInjector, name: 'DowngradeComponentAdapter' });
661
- this.componentRef =
662
- this.componentFactory.create(childInjector, projectableNodes, this.element[0]);
663
- this.viewChangeDetector = this.componentRef.injector.get(core.ChangeDetectorRef);
664
- this.changeDetector = this.componentRef.changeDetectorRef;
665
- this.component = this.componentRef.instance;
666
- // testability hook is commonly added during component bootstrap in
667
- // packages/core/src/application_ref.bootstrap()
668
- // in downgraded application, component creation will take place here as well as adding the
669
- // testability hook.
670
- var testability = this.componentRef.injector.get(core.Testability, null);
671
- if (testability) {
672
- this.componentRef.injector.get(core.TestabilityRegistry)
673
- .registerApplication(this.componentRef.location.nativeElement, testability);
674
- }
675
- hookupNgModel(this.ngModel, this.component);
676
- };
677
- DowngradeComponentAdapter.prototype.setupInputs = function (manuallyAttachView, propagateDigest) {
678
- var _this = this;
679
- if (propagateDigest === void 0) { propagateDigest = true; }
680
- var attrs = this.attrs;
681
- var inputs = this.componentFactory.inputs || [];
682
- var _loop_1 = function (i) {
683
- var input = new PropertyBinding(inputs[i].propName, inputs[i].templateName);
684
- var expr = null;
685
- if (attrs.hasOwnProperty(input.attr)) {
686
- var observeFn_1 = (function (prop) {
687
- var prevValue = INITIAL_VALUE;
688
- return function (currValue) {
689
- // Initially, both `$observe()` and `$watch()` will call this function.
690
- if (!strictEquals(prevValue, currValue)) {
691
- if (prevValue === INITIAL_VALUE) {
692
- prevValue = currValue;
693
- }
694
- _this.updateInput(prop, prevValue, currValue);
695
- prevValue = currValue;
696
- }
697
- };
698
- })(input.prop);
699
- attrs.$observe(input.attr, observeFn_1);
700
- // Use `$watch()` (in addition to `$observe()`) in order to initialize the input in time
701
- // for `ngOnChanges()`. This is necessary if we are already in a `$digest`, which means that
702
- // `ngOnChanges()` (which is called by a watcher) will run before the `$observe()` callback.
703
- var unwatch_1 = this_1.componentScope.$watch(function () {
704
- unwatch_1();
705
- unwatch_1 = null;
706
- observeFn_1(attrs[input.attr]);
707
- });
708
- }
709
- else if (attrs.hasOwnProperty(input.bindAttr)) {
710
- expr = attrs[input.bindAttr];
711
- }
712
- else if (attrs.hasOwnProperty(input.bracketAttr)) {
713
- expr = attrs[input.bracketAttr];
714
- }
715
- else if (attrs.hasOwnProperty(input.bindonAttr)) {
716
- expr = attrs[input.bindonAttr];
717
- }
718
- else if (attrs.hasOwnProperty(input.bracketParenAttr)) {
719
- expr = attrs[input.bracketParenAttr];
720
- }
721
- if (expr != null) {
722
- var watchFn = (function (prop) { return function (currValue, prevValue) { return _this.updateInput(prop, prevValue, currValue); }; })(input.prop);
723
- this_1.componentScope.$watch(expr, watchFn);
724
- }
725
- };
726
- var this_1 = this;
727
- for (var i = 0; i < inputs.length; i++) {
728
- _loop_1(i);
729
- }
730
- // Invoke `ngOnChanges()` and Change Detection (when necessary)
731
- var detectChanges = function () { return _this.changeDetector.detectChanges(); };
732
- var prototype = this.componentFactory.componentType.prototype;
733
- this.implementsOnChanges = !!(prototype && prototype.ngOnChanges);
734
- this.componentScope.$watch(function () { return _this.inputChangeCount; }, this.wrapCallback(function () {
735
- // Invoke `ngOnChanges()`
736
- if (_this.implementsOnChanges) {
737
- var inputChanges = _this.inputChanges;
738
- _this.inputChanges = {};
739
- _this.component.ngOnChanges(inputChanges);
740
- }
741
- _this.viewChangeDetector.markForCheck();
742
- // If opted out of propagating digests, invoke change detection when inputs change.
743
- if (!propagateDigest) {
744
- detectChanges();
745
- }
746
- }));
747
- // If not opted out of propagating digests, invoke change detection on every digest
748
- if (propagateDigest) {
749
- this.componentScope.$watch(this.wrapCallback(detectChanges));
750
- }
751
- // If necessary, attach the view so that it will be dirty-checked.
752
- // (Allow time for the initial input values to be set and `ngOnChanges()` to be called.)
753
- if (manuallyAttachView || !propagateDigest) {
754
- var unwatch_2 = this.componentScope.$watch(function () {
755
- unwatch_2();
756
- unwatch_2 = null;
757
- var appRef = _this.parentInjector.get(core.ApplicationRef);
758
- appRef.attachView(_this.componentRef.hostView);
759
- });
760
- }
761
- };
762
- DowngradeComponentAdapter.prototype.setupOutputs = function () {
763
- var attrs = this.attrs;
764
- var outputs = this.componentFactory.outputs || [];
765
- for (var j = 0; j < outputs.length; j++) {
766
- var output = new PropertyBinding(outputs[j].propName, outputs[j].templateName);
767
- var bindonAttr = output.bindonAttr.substring(0, output.bindonAttr.length - 6);
768
- var bracketParenAttr = "[(" + output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8) + ")]";
769
- // order below is important - first update bindings then evaluate expressions
770
- if (attrs.hasOwnProperty(bindonAttr)) {
771
- this.subscribeToOutput(output, attrs[bindonAttr], true);
772
- }
773
- if (attrs.hasOwnProperty(bracketParenAttr)) {
774
- this.subscribeToOutput(output, attrs[bracketParenAttr], true);
775
- }
776
- if (attrs.hasOwnProperty(output.onAttr)) {
777
- this.subscribeToOutput(output, attrs[output.onAttr]);
778
- }
779
- if (attrs.hasOwnProperty(output.parenAttr)) {
780
- this.subscribeToOutput(output, attrs[output.parenAttr]);
781
- }
782
- }
783
- };
784
- DowngradeComponentAdapter.prototype.subscribeToOutput = function (output, expr, isAssignment) {
785
- var _this = this;
786
- if (isAssignment === void 0) { isAssignment = false; }
787
- var getter = this.$parse(expr);
788
- var setter = getter.assign;
789
- if (isAssignment && !setter) {
790
- throw new Error("Expression '" + expr + "' is not assignable!");
791
- }
792
- var emitter = this.component[output.prop];
793
- if (emitter) {
794
- emitter.subscribe({
795
- next: isAssignment ? function (v) { return setter(_this.scope, v); } :
796
- function (v) { return getter(_this.scope, { '$event': v }); }
797
- });
798
- }
799
- else {
800
- throw new Error("Missing emitter '" + output.prop + "' on component '" + getTypeName(this.componentFactory.componentType) + "'!");
801
- }
802
- };
803
- DowngradeComponentAdapter.prototype.registerCleanup = function () {
804
- var _this = this;
805
- var testabilityRegistry = this.componentRef.injector.get(core.TestabilityRegistry);
806
- var destroyComponentRef = this.wrapCallback(function () { return _this.componentRef.destroy(); });
807
- var destroyed = false;
808
- this.element.on('$destroy', function () {
809
- // The `$destroy` event may have been triggered by the `cleanData()` call in the
810
- // `componentScope` `$destroy` handler below. In that case, we don't want to call
811
- // `componentScope.$destroy()` again.
812
- if (!destroyed)
813
- _this.componentScope.$destroy();
814
- });
815
- this.componentScope.$on('$destroy', function () {
816
- if (!destroyed) {
817
- destroyed = true;
818
- testabilityRegistry.unregisterApplication(_this.componentRef.location.nativeElement);
819
- // The `componentScope` might be getting destroyed, because an ancestor element is being
820
- // removed/destroyed. If that is the case, jqLite/jQuery would normally invoke `cleanData()`
821
- // on the removed element and all descendants.
822
- // https://github.com/angular/angular.js/blob/2e72ea13fa98bebf6ed4b5e3c45eaf5f990ed16f/src/jqLite.js#L349-L355
823
- // https://github.com/jquery/jquery/blob/6984d1747623dbc5e87fd6c261a5b6b1628c107c/src/manipulation.js#L182
824
- //
825
- // Here, however, `destroyComponentRef()` may under some circumstances remove the element
826
- // from the DOM and therefore it will no longer be a descendant of the removed element when
827
- // `cleanData()` is called. This would result in a memory leak, because the element's data
828
- // and event handlers (and all objects directly or indirectly referenced by them) would be
829
- // retained.
830
- //
831
- // To ensure the element is always properly cleaned up, we manually call `cleanData()` on
832
- // this element and its descendants before destroying the `ComponentRef`.
833
- cleanData(_this.element[0]);
834
- destroyComponentRef();
835
- }
836
- });
837
- };
838
- DowngradeComponentAdapter.prototype.getInjector = function () {
839
- return this.componentRef.injector;
840
- };
841
- DowngradeComponentAdapter.prototype.updateInput = function (prop, prevValue, currValue) {
842
- if (this.implementsOnChanges) {
843
- this.inputChanges[prop] = new core.SimpleChange(prevValue, currValue, prevValue === currValue);
844
- }
845
- this.inputChangeCount++;
846
- this.component[prop] = currValue;
847
- };
848
- DowngradeComponentAdapter.prototype.groupProjectableNodes = function () {
849
- var ngContentSelectors = this.componentFactory.ngContentSelectors;
850
- return groupNodesBySelector(ngContentSelectors, this.element.contents());
851
- };
852
- return DowngradeComponentAdapter;
853
- }());
854
- /**
855
- * Group a set of DOM nodes into `ngContent` groups, based on the given content selectors.
856
- */
857
- function groupNodesBySelector(ngContentSelectors, nodes) {
858
- var projectableNodes = [];
859
- for (var i = 0, ii = ngContentSelectors.length; i < ii; ++i) {
860
- projectableNodes[i] = [];
861
- }
862
- for (var j = 0, jj = nodes.length; j < jj; ++j) {
863
- var node = nodes[j];
864
- var ngContentIndex = findMatchingNgContentIndex(node, ngContentSelectors);
865
- if (ngContentIndex != null) {
866
- projectableNodes[ngContentIndex].push(node);
867
- }
868
- }
869
- return projectableNodes;
870
- }
871
- function findMatchingNgContentIndex(element, ngContentSelectors) {
872
- var ngContentIndices = [];
873
- var wildcardNgContentIndex = -1;
874
- for (var i = 0; i < ngContentSelectors.length; i++) {
875
- var selector = ngContentSelectors[i];
876
- if (selector === '*') {
877
- wildcardNgContentIndex = i;
878
- }
879
- else {
880
- if (matchesSelector(element, selector)) {
881
- ngContentIndices.push(i);
882
- }
883
- }
884
- }
885
- ngContentIndices.sort();
886
- if (wildcardNgContentIndex !== -1) {
887
- ngContentIndices.push(wildcardNgContentIndex);
888
- }
889
- return ngContentIndices.length ? ngContentIndices[0] : null;
890
- }
891
- var _matches;
892
- function matchesSelector(el, selector) {
893
- if (!_matches) {
894
- var elProto = Element.prototype;
895
- _matches = elProto.matches || elProto.matchesSelector || elProto.mozMatchesSelector ||
896
- elProto.msMatchesSelector || elProto.oMatchesSelector || elProto.webkitMatchesSelector;
897
- }
898
- return el.nodeType === Node.ELEMENT_NODE ? _matches.call(el, selector) : false;
899
- }
900
-
901
- /**
902
- * @license
903
- * Copyright Google LLC All Rights Reserved.
904
- *
905
- * Use of this source code is governed by an MIT-style license that can be
906
- * found in the LICENSE file at https://angular.io/license
907
- */
908
- function isThenable(obj) {
909
- return !!obj && isFunction(obj.then);
910
- }
911
- /**
912
- * Synchronous, promise-like object.
913
- */
914
- var SyncPromise = /** @class */ (function () {
915
- function SyncPromise() {
916
- this.resolved = false;
917
- this.callbacks = [];
918
- }
919
- SyncPromise.all = function (valuesOrPromises) {
920
- var aggrPromise = new SyncPromise();
921
- var resolvedCount = 0;
922
- var results = [];
923
- var resolve = function (idx, value) {
924
- results[idx] = value;
925
- if (++resolvedCount === valuesOrPromises.length)
926
- aggrPromise.resolve(results);
927
- };
928
- valuesOrPromises.forEach(function (p, idx) {
929
- if (isThenable(p)) {
930
- p.then(function (v) { return resolve(idx, v); });
931
- }
932
- else {
933
- resolve(idx, p);
934
- }
935
- });
936
- return aggrPromise;
937
- };
938
- SyncPromise.prototype.resolve = function (value) {
939
- // Do nothing, if already resolved.
940
- if (this.resolved)
941
- return;
942
- this.value = value;
943
- this.resolved = true;
944
- // Run the queued callbacks.
945
- this.callbacks.forEach(function (callback) { return callback(value); });
946
- this.callbacks.length = 0;
947
- };
948
- SyncPromise.prototype.then = function (callback) {
949
- if (this.resolved) {
950
- callback(this.value);
951
- }
952
- else {
953
- this.callbacks.push(callback);
954
- }
955
- };
956
- return SyncPromise;
957
- }());
958
-
959
- /**
960
- * @description
961
- *
962
- * A helper function that allows an Angular component to be used from AngularJS.
963
- *
964
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
965
- * library for hybrid upgrade apps that support AOT compilation*
966
- *
967
- * This helper function returns a factory function to be used for registering
968
- * an AngularJS wrapper directive for "downgrading" an Angular component.
969
- *
970
- * @usageNotes
971
- * ### Examples
972
- *
973
- * Let's assume that you have an Angular component called `ng2Heroes` that needs
974
- * to be made available in AngularJS templates.
975
- *
976
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes"}
977
- *
978
- * We must create an AngularJS [directive](https://docs.angularjs.org/guide/directive)
979
- * that will make this Angular component available inside AngularJS templates.
980
- * The `downgradeComponent()` function returns a factory function that we
981
- * can use to define the AngularJS directive that wraps the "downgraded" component.
982
- *
983
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes-wrapper"}
984
- *
985
- * For more details and examples on downgrading Angular components to AngularJS components please
986
- * visit the [Upgrade guide](guide/upgrade#using-angular-components-from-angularjs-code).
987
- *
988
- * @param info contains information about the Component that is being downgraded:
989
- *
990
- * - `component: Type<any>`: The type of the Component that will be downgraded
991
- * - `downgradedModule?: string`: The name of the downgraded module (if any) that the component
992
- * "belongs to", as returned by a call to `downgradeModule()`. It is the module, whose
993
- * corresponding Angular module will be bootstrapped, when the component needs to be instantiated.
994
- * <br />
995
- * (This option is only necessary when using `downgradeModule()` to downgrade more than one
996
- * Angular module.)
997
- * - `propagateDigest?: boolean`: Whether to perform {@link ChangeDetectorRef#detectChanges
998
- * change detection} on the component on every
999
- * [$digest](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest). If set to `false`,
1000
- * change detection will still be performed when any of the component's inputs changes.
1001
- * (Default: true)
1002
- *
1003
- * @returns a factory function that can be used to register the component in an
1004
- * AngularJS module.
1005
- *
1006
- * @publicApi
1007
- */
1008
- function downgradeComponent(info) {
1009
- var directiveFactory = function ($compile, $injector, $parse) {
1010
- // When using `downgradeModule()`, we need to handle certain things specially. For example:
1011
- // - We always need to attach the component view to the `ApplicationRef` for it to be
1012
- // dirty-checked.
1013
- // - We need to ensure callbacks to Angular APIs (e.g. change detection) are run inside the
1014
- // Angular zone.
1015
- // NOTE: This is not needed, when using `UpgradeModule`, because `$digest()` will be run
1016
- // inside the Angular zone (except if explicitly escaped, in which case we shouldn't
1017
- // force it back in).
1018
- var isNgUpgradeLite = getUpgradeAppType($injector) === 3 /* Lite */;
1019
- var wrapCallback = !isNgUpgradeLite ? function (cb) { return cb; } : function (cb) { return function () { return core.NgZone.isInAngularZone() ? cb() : ngZone.run(cb); }; };
1020
- var ngZone;
1021
- // When downgrading multiple modules, special handling is needed wrt injectors.
1022
- var hasMultipleDowngradedModules = isNgUpgradeLite && (getDowngradedModuleCount($injector) > 1);
1023
- return {
1024
- restrict: 'E',
1025
- terminal: true,
1026
- require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
1027
- link: function (scope, element, attrs, required) {
1028
- // We might have to compile the contents asynchronously, because this might have been
1029
- // triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have
1030
- // been compiled.
1031
- var ngModel = required[1];
1032
- var parentInjector = required[0];
1033
- var moduleInjector = undefined;
1034
- var ranAsync = false;
1035
- if (!parentInjector || hasMultipleDowngradedModules) {
1036
- var downgradedModule = info.downgradedModule || '';
1037
- var lazyModuleRefKey = "" + LAZY_MODULE_REF + downgradedModule;
1038
- var attemptedAction = "instantiating component '" + getTypeName(info.component) + "'";
1039
- validateInjectionKey($injector, downgradedModule, lazyModuleRefKey, attemptedAction);
1040
- var lazyModuleRef = $injector.get(lazyModuleRefKey);
1041
- moduleInjector = lazyModuleRef.injector || lazyModuleRef.promise;
1042
- }
1043
- // Notes:
1044
- //
1045
- // There are two injectors: `finalModuleInjector` and `finalParentInjector` (they might be
1046
- // the same instance, but that is irrelevant):
1047
- // - `finalModuleInjector` is used to retrieve `ComponentFactoryResolver`, thus it must be
1048
- // on the same tree as the `NgModule` that declares this downgraded component.
1049
- // - `finalParentInjector` is used for all other injection purposes.
1050
- // (Note that Angular knows to only traverse the component-tree part of that injector,
1051
- // when looking for an injectable and then switch to the module injector.)
1052
- //
1053
- // There are basically three cases:
1054
- // - If there is no parent component (thus no `parentInjector`), we bootstrap the downgraded
1055
- // `NgModule` and use its injector as both `finalModuleInjector` and
1056
- // `finalParentInjector`.
1057
- // - If there is a parent component (and thus a `parentInjector`) and we are sure that it
1058
- // belongs to the same `NgModule` as this downgraded component (e.g. because there is only
1059
- // one downgraded module, we use that `parentInjector` as both `finalModuleInjector` and
1060
- // `finalParentInjector`.
1061
- // - If there is a parent component, but it may belong to a different `NgModule`, then we
1062
- // use the `parentInjector` as `finalParentInjector` and this downgraded component's
1063
- // declaring `NgModule`'s injector as `finalModuleInjector`.
1064
- // Note 1: If the `NgModule` is already bootstrapped, we just get its injector (we don't
1065
- // bootstrap again).
1066
- // Note 2: It is possible that (while there are multiple downgraded modules) this
1067
- // downgraded component and its parent component both belong to the same NgModule.
1068
- // In that case, we could have used the `parentInjector` as both
1069
- // `finalModuleInjector` and `finalParentInjector`, but (for simplicity) we are
1070
- // treating this case as if they belong to different `NgModule`s. That doesn't
1071
- // really affect anything, since `parentInjector` has `moduleInjector` as ancestor
1072
- // and trying to resolve `ComponentFactoryResolver` from either one will return
1073
- // the same instance.
1074
- // If there is a parent component, use its injector as parent injector.
1075
- // If this is a "top-level" Angular component, use the module injector.
1076
- var finalParentInjector = parentInjector || moduleInjector;
1077
- // If this is a "top-level" Angular component or the parent component may belong to a
1078
- // different `NgModule`, use the module injector for module-specific dependencies.
1079
- // If there is a parent component that belongs to the same `NgModule`, use its injector.
1080
- var finalModuleInjector = moduleInjector || parentInjector;
1081
- var doDowngrade = function (injector, moduleInjector) {
1082
- // Retrieve `ComponentFactoryResolver` from the injector tied to the `NgModule` this
1083
- // component belongs to.
1084
- var componentFactoryResolver = moduleInjector.get(core.ComponentFactoryResolver);
1085
- var componentFactory = componentFactoryResolver.resolveComponentFactory(info.component);
1086
- if (!componentFactory) {
1087
- throw new Error("Expecting ComponentFactory for: " + getTypeName(info.component));
1088
- }
1089
- var injectorPromise = new ParentInjectorPromise(element);
1090
- var facade = new DowngradeComponentAdapter(element, attrs, scope, ngModel, injector, $compile, $parse, componentFactory, wrapCallback);
1091
- var projectableNodes = facade.compileContents();
1092
- facade.createComponent(projectableNodes);
1093
- facade.setupInputs(isNgUpgradeLite, info.propagateDigest);
1094
- facade.setupOutputs();
1095
- facade.registerCleanup();
1096
- injectorPromise.resolve(facade.getInjector());
1097
- if (ranAsync) {
1098
- // If this is run async, it is possible that it is not run inside a
1099
- // digest and initial input values will not be detected.
1100
- scope.$evalAsync(function () { });
1101
- }
1102
- };
1103
- var downgradeFn = !isNgUpgradeLite ? doDowngrade : function (pInjector, mInjector) {
1104
- if (!ngZone) {
1105
- ngZone = pInjector.get(core.NgZone);
1106
- }
1107
- wrapCallback(function () { return doDowngrade(pInjector, mInjector); })();
1108
- };
1109
- // NOTE:
1110
- // Not using `ParentInjectorPromise.all()` (which is inherited from `SyncPromise`), because
1111
- // Closure Compiler (or some related tool) complains:
1112
- // `TypeError: ...$src$downgrade_component_ParentInjectorPromise.all is not a function`
1113
- SyncPromise.all([finalParentInjector, finalModuleInjector])
1114
- .then(function (_a) {
1115
- var _b = __read(_a, 2), pInjector = _b[0], mInjector = _b[1];
1116
- return downgradeFn(pInjector, mInjector);
1117
- });
1118
- ranAsync = true;
1119
- }
1120
- };
1121
- };
1122
- // bracket-notation because of closure - see #14441
1123
- directiveFactory['$inject'] = [$COMPILE, $INJECTOR, $PARSE];
1124
- return directiveFactory;
1125
- }
1126
- /**
1127
- * Synchronous promise-like object to wrap parent injectors,
1128
- * to preserve the synchronous nature of AngularJS's `$compile`.
1129
- */
1130
- var ParentInjectorPromise = /** @class */ (function (_super) {
1131
- __extends(ParentInjectorPromise, _super);
1132
- function ParentInjectorPromise(element) {
1133
- var _this = _super.call(this) || this;
1134
- _this.element = element;
1135
- _this.injectorKey = controllerKey(INJECTOR_KEY);
1136
- // Store the promise on the element.
1137
- element.data(_this.injectorKey, _this);
1138
- return _this;
1139
- }
1140
- ParentInjectorPromise.prototype.resolve = function (injector) {
1141
- // Store the real injector on the element.
1142
- this.element.data(this.injectorKey, injector);
1143
- // Release the element to prevent memory leaks.
1144
- this.element = null;
1145
- // Resolve the promise.
1146
- _super.prototype.resolve.call(this, injector);
1147
- };
1148
- return ParentInjectorPromise;
1149
- }(SyncPromise));
1150
-
1151
- /**
1152
- * @license
1153
- * Copyright Google LLC All Rights Reserved.
1154
- *
1155
- * Use of this source code is governed by an MIT-style license that can be
1156
- * found in the LICENSE file at https://angular.io/license
1157
- */
1158
- /**
1159
- * @description
1160
- *
1161
- * A helper function to allow an Angular service to be accessible from AngularJS.
1162
- *
1163
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
1164
- * library for hybrid upgrade apps that support AOT compilation*
1165
- *
1166
- * This helper function returns a factory function that provides access to the Angular
1167
- * service identified by the `token` parameter.
1168
- *
1169
- * @usageNotes
1170
- * ### Examples
1171
- *
1172
- * First ensure that the service to be downgraded is provided in an `NgModule`
1173
- * that will be part of the upgrade application. For example, let's assume we have
1174
- * defined `HeroesService`
1175
- *
1176
- * {@example upgrade/static/ts/full/module.ts region="ng2-heroes-service"}
1177
- *
1178
- * and that we have included this in our upgrade app `NgModule`
1179
- *
1180
- * {@example upgrade/static/ts/full/module.ts region="ng2-module"}
1181
- *
1182
- * Now we can register the `downgradeInjectable` factory function for the service
1183
- * on an AngularJS module.
1184
- *
1185
- * {@example upgrade/static/ts/full/module.ts region="downgrade-ng2-heroes-service"}
1186
- *
1187
- * Inside an AngularJS component's controller we can get hold of the
1188
- * downgraded service via the name we gave when downgrading.
1189
- *
1190
- * {@example upgrade/static/ts/full/module.ts region="example-app"}
1191
- *
1192
- * <div class="alert is-important">
1193
- *
1194
- * When using `downgradeModule()`, downgraded injectables will not be available until the Angular
1195
- * module that provides them is instantiated. In order to be safe, you need to ensure that the
1196
- * downgraded injectables are not used anywhere _outside_ the part of the app where it is
1197
- * guaranteed that their module has been instantiated.
1198
- *
1199
- * For example, it is _OK_ to use a downgraded service in an upgraded component that is only used
1200
- * from a downgraded Angular component provided by the same Angular module as the injectable, but
1201
- * it is _not OK_ to use it in an AngularJS component that may be used independently of Angular or
1202
- * use it in a downgraded Angular component from a different module.
1203
- *
1204
- * </div>
1205
- *
1206
- * @param token an `InjectionToken` that identifies a service provided from Angular.
1207
- * @param downgradedModule the name of the downgraded module (if any) that the injectable
1208
- * "belongs to", as returned by a call to `downgradeModule()`. It is the module, whose injector will
1209
- * be used for instantiating the injectable.<br />
1210
- * (This option is only necessary when using `downgradeModule()` to downgrade more than one Angular
1211
- * module.)
1212
- *
1213
- * @returns a [factory function](https://docs.angularjs.org/guide/di) that can be
1214
- * used to register the service on an AngularJS module.
1215
- *
1216
- * @publicApi
1217
- */
1218
- function downgradeInjectable(token, downgradedModule) {
1219
- if (downgradedModule === void 0) { downgradedModule = ''; }
1220
- var factory = function ($injector) {
1221
- var injectorKey = "" + INJECTOR_KEY + downgradedModule;
1222
- var injectableName = isFunction(token) ? getTypeName(token) : String(token);
1223
- var attemptedAction = "instantiating injectable '" + injectableName + "'";
1224
- validateInjectionKey($injector, downgradedModule, injectorKey, attemptedAction);
1225
- try {
1226
- var injector = $injector.get(injectorKey);
1227
- return injector.get(token);
1228
- }
1229
- catch (err) {
1230
- throw new Error("Error while " + attemptedAction + ": " + (err.message || err));
1231
- }
1232
- };
1233
- factory['$inject'] = [$INJECTOR];
1234
- return factory;
1235
- }
1236
-
1237
- /**
1238
- * @license
1239
- * Copyright Google LLC All Rights Reserved.
1240
- *
1241
- * Use of this source code is governed by an MIT-style license that can be
1242
- * found in the LICENSE file at https://angular.io/license
1243
- */
1244
- /**
1245
- * @publicApi
1246
- */
1247
- var VERSION = new core.Version('13.0.0-next.8');
1248
-
1249
- /**
1250
- * @license
1251
- * Copyright Google LLC All Rights Reserved.
1252
- *
1253
- * Use of this source code is governed by an MIT-style license that can be
1254
- * found in the LICENSE file at https://angular.io/license
1255
- */
1256
- // We have to do a little dance to get the ng1 injector into the module injector.
1257
- // We store the ng1 injector so that the provider in the module injector can access it
1258
- // Then we "get" the ng1 injector from the module injector, which triggers the provider to read
1259
- // the stored injector and release the reference to it.
1260
- var tempInjectorRef = null;
1261
- function setTempInjectorRef(injector) {
1262
- tempInjectorRef = injector;
1263
- }
1264
- function injectorFactory() {
1265
- if (!tempInjectorRef) {
1266
- throw new Error('Trying to get the AngularJS injector before it being set.');
1267
- }
1268
- var injector = tempInjectorRef;
1269
- tempInjectorRef = null; // clear the value to prevent memory leaks
1270
- return injector;
1271
- }
1272
- function rootScopeFactory(i) {
1273
- return i.get('$rootScope');
1274
- }
1275
- function compileFactory(i) {
1276
- return i.get('$compile');
1277
- }
1278
- function parseFactory(i) {
1279
- return i.get('$parse');
1280
- }
1281
- var angular1Providers = [
1282
- // We must use exported named functions for the ng2 factories to keep the compiler happy:
1283
- // > Metadata collected contains an error that will be reported at runtime:
1284
- // > Function calls are not supported.
1285
- // > Consider replacing the function or lambda with a reference to an exported function
1286
- { provide: '$injector', useFactory: injectorFactory, deps: [] },
1287
- { provide: '$rootScope', useFactory: rootScopeFactory, deps: ['$injector'] },
1288
- { provide: '$compile', useFactory: compileFactory, deps: ['$injector'] },
1289
- { provide: '$parse', useFactory: parseFactory, deps: ['$injector'] }
1290
- ];
1291
-
1292
- /**
1293
- * @license
1294
- * Copyright Google LLC All Rights Reserved.
1295
- *
1296
- * Use of this source code is governed by an MIT-style license that can be
1297
- * found in the LICENSE file at https://angular.io/license
1298
- */
1299
- var NgAdapterInjector = /** @class */ (function () {
1300
- function NgAdapterInjector(modInjector) {
1301
- this.modInjector = modInjector;
1302
- }
1303
- // When Angular locate a service in the component injector tree, the not found value is set to
1304
- // `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR`. In such a case we should not walk up to the module
1305
- // injector.
1306
- // AngularJS only supports a single tree and should always check the module injector.
1307
- NgAdapterInjector.prototype.get = function (token, notFoundValue) {
1308
- if (notFoundValue === core.ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR) {
1309
- return notFoundValue;
1310
- }
1311
- return this.modInjector.get(token, notFoundValue);
1312
- };
1313
- return NgAdapterInjector;
1314
- }());
1315
-
1316
- /**
1317
- * @license
1318
- * Copyright Google LLC All Rights Reserved.
1319
- *
1320
- * Use of this source code is governed by an MIT-style license that can be
1321
- * found in the LICENSE file at https://angular.io/license
1322
- */
1323
- var moduleUid = 0;
1324
- /**
1325
- * @description
1326
- *
1327
- * A helper function for creating an AngularJS module that can bootstrap an Angular module
1328
- * "on-demand" (possibly lazily) when a {@link downgradeComponent downgraded component} needs to be
1329
- * instantiated.
1330
- *
1331
- * *Part of the [upgrade/static](api?query=upgrade/static) library for hybrid upgrade apps that
1332
- * support AOT compilation.*
1333
- *
1334
- * It allows loading/bootstrapping the Angular part of a hybrid application lazily and not having to
1335
- * pay the cost up-front. For example, you can have an AngularJS application that uses Angular for
1336
- * specific routes and only instantiate the Angular modules if/when the user visits one of these
1337
- * routes.
1338
- *
1339
- * The Angular module will be bootstrapped once (when requested for the first time) and the same
1340
- * reference will be used from that point onwards.
1341
- *
1342
- * `downgradeModule()` requires either an `NgModuleFactory` or a function:
1343
- * - `NgModuleFactory`: If you pass an `NgModuleFactory`, it will be used to instantiate a module
1344
- * using `platformBrowser`'s {@link PlatformRef#bootstrapModuleFactory bootstrapModuleFactory()}.
1345
- * - `Function`: If you pass a function, it is expected to return a promise resolving to an
1346
- * `NgModuleRef`. The function is called with an array of extra {@link StaticProvider Providers}
1347
- * that are expected to be available from the returned `NgModuleRef`'s `Injector`.
1348
- *
1349
- * `downgradeModule()` returns the name of the created AngularJS wrapper module. You can use it to
1350
- * declare a dependency in your main AngularJS module.
1351
- *
1352
- * {@example upgrade/static/ts/lite/module.ts region="basic-how-to"}
1353
- *
1354
- * For more details on how to use `downgradeModule()` see
1355
- * [Upgrading for Performance](guide/upgrade-performance).
1356
- *
1357
- * @usageNotes
1358
- *
1359
- * Apart from `UpgradeModule`, you can use the rest of the `upgrade/static` helpers as usual to
1360
- * build a hybrid application. Note that the Angular pieces (e.g. downgraded services) will not be
1361
- * available until the downgraded module has been bootstrapped, i.e. by instantiating a downgraded
1362
- * component.
1363
- *
1364
- * <div class="alert is-important">
1365
- *
1366
- * You cannot use `downgradeModule()` and `UpgradeModule` in the same hybrid application.<br />
1367
- * Use one or the other.
1368
- *
1369
- * </div>
1370
- *
1371
- * ### Differences with `UpgradeModule`
1372
- *
1373
- * Besides their different API, there are two important internal differences between
1374
- * `downgradeModule()` and `UpgradeModule` that affect the behavior of hybrid applications:
1375
- *
1376
- * 1. Unlike `UpgradeModule`, `downgradeModule()` does not bootstrap the main AngularJS module
1377
- * inside the {@link NgZone Angular zone}.
1378
- * 2. Unlike `UpgradeModule`, `downgradeModule()` does not automatically run a
1379
- * [$digest()](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest) when changes are
1380
- * detected in the Angular part of the application.
1381
- *
1382
- * What this means is that applications using `UpgradeModule` will run change detection more
1383
- * frequently in order to ensure that both frameworks are properly notified about possible changes.
1384
- * This will inevitably result in more change detection runs than necessary.
1385
- *
1386
- * `downgradeModule()`, on the other side, does not try to tie the two change detection systems as
1387
- * tightly, restricting the explicit change detection runs only to cases where it knows it is
1388
- * necessary (e.g. when the inputs of a downgraded component change). This improves performance,
1389
- * especially in change-detection-heavy applications, but leaves it up to the developer to manually
1390
- * notify each framework as needed.
1391
- *
1392
- * For a more detailed discussion of the differences and their implications, see
1393
- * [Upgrading for Performance](guide/upgrade-performance).
1394
- *
1395
- * <div class="alert is-helpful">
1396
- *
1397
- * You can manually trigger a change detection run in AngularJS using
1398
- * [scope.$apply(...)](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$apply) or
1399
- * [$rootScope.$digest()](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$digest).
1400
- *
1401
- * You can manually trigger a change detection run in Angular using {@link NgZone#run
1402
- * ngZone.run(...)}.
1403
- *
1404
- * </div>
1405
- *
1406
- * ### Downgrading multiple modules
1407
- *
1408
- * It is possible to downgrade multiple modules and include them in an AngularJS application. In
1409
- * that case, each downgraded module will be bootstrapped when an associated downgraded component or
1410
- * injectable needs to be instantiated.
1411
- *
1412
- * Things to keep in mind, when downgrading multiple modules:
1413
- *
1414
- * - Each downgraded component/injectable needs to be explicitly associated with a downgraded
1415
- * module. See `downgradeComponent()` and `downgradeInjectable()` for more details.
1416
- *
1417
- * - If you want some injectables to be shared among all downgraded modules, you can provide them as
1418
- * `StaticProvider`s, when creating the `PlatformRef` (e.g. via `platformBrowser` or
1419
- * `platformBrowserDynamic`).
1420
- *
1421
- * - When using {@link PlatformRef#bootstrapmodule `bootstrapModule()`} or
1422
- * {@link PlatformRef#bootstrapmodulefactory `bootstrapModuleFactory()`} to bootstrap the
1423
- * downgraded modules, each one is considered a "root" module. As a consequence, a new instance
1424
- * will be created for every injectable provided in `"root"` (via
1425
- * {@link Injectable#providedIn `providedIn`}).
1426
- * If this is not your intention, you can have a shared module (that will act as act as the "root"
1427
- * module) and create all downgraded modules using that module's injector:
1428
- *
1429
- * {@example upgrade/static/ts/lite-multi-shared/module.ts region="shared-root-module"}
1430
- *
1431
- * @publicApi
1432
- */
1433
- function downgradeModule(moduleFactoryOrBootstrapFn) {
1434
- var lazyModuleName = UPGRADE_MODULE_NAME + ".lazy" + ++moduleUid;
1435
- var lazyModuleRefKey = "" + LAZY_MODULE_REF + lazyModuleName;
1436
- var lazyInjectorKey = "" + INJECTOR_KEY + lazyModuleName;
1437
- var bootstrapFn = isFunction(moduleFactoryOrBootstrapFn) ?
1438
- moduleFactoryOrBootstrapFn :
1439
- function (extraProviders) { return platformBrowser.platformBrowser(extraProviders).bootstrapModuleFactory(moduleFactoryOrBootstrapFn); };
1440
- var injector;
1441
- // Create an ng1 module to bootstrap.
1442
- module_(lazyModuleName, [])
1443
- .constant(UPGRADE_APP_TYPE_KEY, 3 /* Lite */)
1444
- .factory(INJECTOR_KEY, [lazyInjectorKey, identity])
1445
- .factory(lazyInjectorKey, function () {
1446
- if (!injector) {
1447
- throw new Error('Trying to get the Angular injector before bootstrapping the corresponding ' +
1448
- 'Angular module.');
1449
- }
1450
- return injector;
1451
- })
1452
- .factory(LAZY_MODULE_REF, [lazyModuleRefKey, identity])
1453
- .factory(lazyModuleRefKey, [
1454
- $INJECTOR,
1455
- function ($injector) {
1456
- setTempInjectorRef($injector);
1457
- var result = {
1458
- promise: bootstrapFn(angular1Providers).then(function (ref) {
1459
- injector = result.injector = new NgAdapterInjector(ref.injector);
1460
- injector.get($INJECTOR);
1461
- // Destroy the AngularJS app once the Angular `PlatformRef` is destroyed.
1462
- // This does not happen in a typical SPA scenario, but it might be useful for
1463
- // other use-cases where disposing of an Angular/AngularJS app is necessary
1464
- // (such as Hot Module Replacement (HMR)).
1465
- // See https://github.com/angular/angular/issues/39935.
1466
- injector.get(core.PlatformRef).onDestroy(function () { return destroyApp($injector); });
1467
- return injector;
1468
- })
1469
- };
1470
- return result;
1471
- }
1472
- ])
1473
- .config([
1474
- $INJECTOR, $PROVIDE,
1475
- function ($injector, $provide) {
1476
- $provide.constant(DOWNGRADED_MODULE_COUNT_KEY, getDowngradedModuleCount($injector) + 1);
1477
- }
1478
- ]);
1479
- return lazyModuleName;
1480
- }
1481
- function identity(x) {
1482
- return x;
1483
- }
1484
-
1485
- // Constants
1486
- var REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
1487
- // Classes
1488
- var UpgradeHelper = /** @class */ (function () {
1489
- function UpgradeHelper(injector, name, elementRef, directive) {
1490
- this.name = name;
1491
- this.$injector = injector.get($INJECTOR);
1492
- this.$compile = this.$injector.get($COMPILE);
1493
- this.$controller = this.$injector.get($CONTROLLER);
1494
- this.element = elementRef.nativeElement;
1495
- this.$element = element(this.element);
1496
- this.directive = directive || UpgradeHelper.getDirective(this.$injector, name);
1497
- }
1498
- UpgradeHelper.getDirective = function ($injector, name) {
1499
- var directives = $injector.get(name + 'Directive');
1500
- if (directives.length > 1) {
1501
- throw new Error("Only support single directive definition for: " + name);
1502
- }
1503
- var directive = directives[0];
1504
- // AngularJS will transform `link: xyz` to `compile: () => xyz`. So we can only tell there was a
1505
- // user-defined `compile` if there is no `link`. In other cases, we will just ignore `compile`.
1506
- if (directive.compile && !directive.link)
1507
- notSupported(name, 'compile');
1508
- if (directive.replace)
1509
- notSupported(name, 'replace');
1510
- if (directive.terminal)
1511
- notSupported(name, 'terminal');
1512
- return directive;
1513
- };
1514
- UpgradeHelper.getTemplate = function ($injector, directive, fetchRemoteTemplate, $element) {
1515
- if (fetchRemoteTemplate === void 0) { fetchRemoteTemplate = false; }
1516
- if (directive.template !== undefined) {
1517
- return getOrCall(directive.template, $element);
1518
- }
1519
- else if (directive.templateUrl) {
1520
- var $templateCache_1 = $injector.get($TEMPLATE_CACHE);
1521
- var url_1 = getOrCall(directive.templateUrl, $element);
1522
- var template = $templateCache_1.get(url_1);
1523
- if (template !== undefined) {
1524
- return template;
1525
- }
1526
- else if (!fetchRemoteTemplate) {
1527
- throw new Error('loading directive templates asynchronously is not supported');
1528
- }
1529
- return new Promise(function (resolve, reject) {
1530
- var $httpBackend = $injector.get($HTTP_BACKEND);
1531
- $httpBackend('GET', url_1, null, function (status, response) {
1532
- if (status === 200) {
1533
- resolve($templateCache_1.put(url_1, response));
1534
- }
1535
- else {
1536
- reject("GET component template from '" + url_1 + "' returned '" + status + ": " + response + "'");
1537
- }
1538
- });
1539
- });
1540
- }
1541
- else {
1542
- throw new Error("Directive '" + directive.name + "' is not a component, it is missing template.");
1543
- }
1544
- };
1545
- UpgradeHelper.prototype.buildController = function (controllerType, $scope) {
1546
- // TODO: Document that we do not pre-assign bindings on the controller instance.
1547
- // Quoted properties below so that this code can be optimized with Closure Compiler.
1548
- var locals = { '$scope': $scope, '$element': this.$element };
1549
- var controller = this.$controller(controllerType, locals, null, this.directive.controllerAs);
1550
- this.$element.data(controllerKey(this.directive.name), controller);
1551
- return controller;
1552
- };
1553
- UpgradeHelper.prototype.compileTemplate = function (template) {
1554
- if (template === undefined) {
1555
- template =
1556
- UpgradeHelper.getTemplate(this.$injector, this.directive, false, this.$element);
1557
- }
1558
- return this.compileHtml(template);
1559
- };
1560
- UpgradeHelper.prototype.onDestroy = function ($scope, controllerInstance) {
1561
- if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
1562
- controllerInstance.$onDestroy();
1563
- }
1564
- $scope.$destroy();
1565
- cleanData(this.element);
1566
- };
1567
- UpgradeHelper.prototype.prepareTransclusion = function () {
1568
- var _this = this;
1569
- var transclude = this.directive.transclude;
1570
- var contentChildNodes = this.extractChildNodes();
1571
- var attachChildrenFn = function (scope, cloneAttachFn) {
1572
- // Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
1573
- // `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
1574
- // there will be no transclusion scope here.
1575
- // Provide a dummy `scope.$destroy()` method to prevent `cloneAttachFn` from throwing.
1576
- scope = scope || { $destroy: function () { return undefined; } };
1577
- return cloneAttachFn($template, scope);
1578
- };
1579
- var $template = contentChildNodes;
1580
- if (transclude) {
1581
- var slots_1 = Object.create(null);
1582
- if (typeof transclude === 'object') {
1583
- $template = [];
1584
- var slotMap_1 = Object.create(null);
1585
- var filledSlots_1 = Object.create(null);
1586
- // Parse the element selectors.
1587
- Object.keys(transclude).forEach(function (slotName) {
1588
- var selector = transclude[slotName];
1589
- var optional = selector.charAt(0) === '?';
1590
- selector = optional ? selector.substring(1) : selector;
1591
- slotMap_1[selector] = slotName;
1592
- slots_1[slotName] = null; // `null`: Defined but not yet filled.
1593
- filledSlots_1[slotName] = optional; // Consider optional slots as filled.
1594
- });
1595
- // Add the matching elements into their slot.
1596
- contentChildNodes.forEach(function (node) {
1597
- var slotName = slotMap_1[directiveNormalize(node.nodeName.toLowerCase())];
1598
- if (slotName) {
1599
- filledSlots_1[slotName] = true;
1600
- slots_1[slotName] = slots_1[slotName] || [];
1601
- slots_1[slotName].push(node);
1602
- }
1603
- else {
1604
- $template.push(node);
1605
- }
1606
- });
1607
- // Check for required slots that were not filled.
1608
- Object.keys(filledSlots_1).forEach(function (slotName) {
1609
- if (!filledSlots_1[slotName]) {
1610
- throw new Error("Required transclusion slot '" + slotName + "' on directive: " + _this.name);
1611
- }
1612
- });
1613
- Object.keys(slots_1).filter(function (slotName) { return slots_1[slotName]; }).forEach(function (slotName) {
1614
- var nodes = slots_1[slotName];
1615
- slots_1[slotName] = function (scope, cloneAttach) {
1616
- return cloneAttach(nodes, scope);
1617
- };
1618
- });
1619
- }
1620
- // Attach `$$slots` to default slot transclude fn.
1621
- attachChildrenFn.$$slots = slots_1;
1622
- // AngularJS v1.6+ ignores empty or whitespace-only transcluded text nodes. But Angular
1623
- // removes all text content after the first interpolation and updates it later, after
1624
- // evaluating the expressions. This would result in AngularJS failing to recognize text
1625
- // nodes that start with an interpolation as transcluded content and use the fallback
1626
- // content instead.
1627
- // To avoid this issue, we add a
1628
- // [zero-width non-joiner character](https://en.wikipedia.org/wiki/Zero-width_non-joiner)
1629
- // to empty text nodes (which can only be a result of Angular removing their initial content).
1630
- // NOTE: Transcluded text content that starts with whitespace followed by an interpolation
1631
- // will still fail to be detected by AngularJS v1.6+
1632
- $template.forEach(function (node) {
1633
- if (node.nodeType === Node.TEXT_NODE && !node.nodeValue) {
1634
- node.nodeValue = '\u200C';
1635
- }
1636
- });
1637
- }
1638
- return attachChildrenFn;
1639
- };
1640
- UpgradeHelper.prototype.resolveAndBindRequiredControllers = function (controllerInstance) {
1641
- var directiveRequire = this.getDirectiveRequire();
1642
- var requiredControllers = this.resolveRequire(directiveRequire);
1643
- if (controllerInstance && this.directive.bindToController && isMap(directiveRequire)) {
1644
- var requiredControllersMap_1 = requiredControllers;
1645
- Object.keys(requiredControllersMap_1).forEach(function (key) {
1646
- controllerInstance[key] = requiredControllersMap_1[key];
1647
- });
1648
- }
1649
- return requiredControllers;
1650
- };
1651
- UpgradeHelper.prototype.compileHtml = function (html) {
1652
- this.element.innerHTML = html;
1653
- return this.$compile(this.element.childNodes);
1654
- };
1655
- UpgradeHelper.prototype.extractChildNodes = function () {
1656
- var childNodes = [];
1657
- var childNode;
1658
- while (childNode = this.element.firstChild) {
1659
- this.element.removeChild(childNode);
1660
- childNodes.push(childNode);
1661
- }
1662
- return childNodes;
1663
- };
1664
- UpgradeHelper.prototype.getDirectiveRequire = function () {
1665
- var require = this.directive.require || (this.directive.controller && this.directive.name);
1666
- if (isMap(require)) {
1667
- Object.keys(require).forEach(function (key) {
1668
- var value = require[key];
1669
- var match = value.match(REQUIRE_PREFIX_RE);
1670
- var name = value.substring(match[0].length);
1671
- if (!name) {
1672
- require[key] = match[0] + key;
1673
- }
1674
- });
1675
- }
1676
- return require;
1677
- };
1678
- UpgradeHelper.prototype.resolveRequire = function (require, controllerInstance) {
1679
- var _this = this;
1680
- if (!require) {
1681
- return null;
1682
- }
1683
- else if (Array.isArray(require)) {
1684
- return require.map(function (req) { return _this.resolveRequire(req); });
1685
- }
1686
- else if (typeof require === 'object') {
1687
- var value_1 = {};
1688
- Object.keys(require).forEach(function (key) { return value_1[key] = _this.resolveRequire(require[key]); });
1689
- return value_1;
1690
- }
1691
- else if (typeof require === 'string') {
1692
- var match = require.match(REQUIRE_PREFIX_RE);
1693
- var inheritType = match[1] || match[3];
1694
- var name = require.substring(match[0].length);
1695
- var isOptional = !!match[2];
1696
- var searchParents = !!inheritType;
1697
- var startOnParent = inheritType === '^^';
1698
- var ctrlKey = controllerKey(name);
1699
- var elem = startOnParent ? this.$element.parent() : this.$element;
1700
- var value = searchParents ? elem.inheritedData(ctrlKey) : elem.data(ctrlKey);
1701
- if (!value && !isOptional) {
1702
- throw new Error("Unable to find required '" + require + "' in upgraded directive '" + this.name + "'.");
1703
- }
1704
- return value;
1705
- }
1706
- else {
1707
- throw new Error("Unrecognized 'require' syntax on upgraded directive '" + this.name + "': " + require);
1708
- }
1709
- };
1710
- return UpgradeHelper;
1711
- }());
1712
- function getOrCall(property) {
1713
- var args = [];
1714
- for (var _i = 1; _i < arguments.length; _i++) {
1715
- args[_i - 1] = arguments[_i];
1716
- }
1717
- return isFunction(property) ? property.apply(void 0, __spreadArray([], __read(args), false)) : property;
1718
- }
1719
- // NOTE: Only works for `typeof T !== 'object'`.
1720
- function isMap(value) {
1721
- return value && !Array.isArray(value) && typeof value === 'object';
1722
- }
1723
- function notSupported(name, feature) {
1724
- throw new Error("Upgraded directive '" + name + "' contains unsupported feature: '" + feature + "'.");
1725
- }
1726
-
1727
- /**
1728
- * @license
1729
- * Copyright Google LLC All Rights Reserved.
1730
- *
1731
- * Use of this source code is governed by an MIT-style license that can be
1732
- * found in the LICENSE file at https://angular.io/license
1733
- */
1734
- var NOT_SUPPORTED = 'NOT_SUPPORTED';
1735
- var INITIAL_VALUE$1 = {
1736
- __UNINITIALIZED__: true
1737
- };
1738
- var Bindings = /** @class */ (function () {
1739
- function Bindings() {
1740
- this.twoWayBoundProperties = [];
1741
- this.twoWayBoundLastValues = [];
1742
- this.expressionBoundProperties = [];
1743
- this.propertyToOutputMap = {};
1744
- }
1745
- return Bindings;
1746
- }());
1747
- /**
1748
- * @description
1749
- *
1750
- * A helper class that allows an AngularJS component to be used from Angular.
1751
- *
1752
- * *Part of the [upgrade/static](api?query=upgrade%2Fstatic)
1753
- * library for hybrid upgrade apps that support AOT compilation.*
1754
- *
1755
- * This helper class should be used as a base class for creating Angular directives
1756
- * that wrap AngularJS components that need to be "upgraded".
1757
- *
1758
- * @usageNotes
1759
- * ### Examples
1760
- *
1761
- * Let's assume that you have an AngularJS component called `ng1Hero` that needs
1762
- * to be made available in Angular templates.
1763
- *
1764
- * {@example upgrade/static/ts/full/module.ts region="ng1-hero"}
1765
- *
1766
- * We must create a `Directive` that will make this AngularJS component
1767
- * available inside Angular templates.
1768
- *
1769
- * {@example upgrade/static/ts/full/module.ts region="ng1-hero-wrapper"}
1770
- *
1771
- * In this example you can see that we must derive from the `UpgradeComponent`
1772
- * base class but also provide an {@link Directive `@Directive`} decorator. This is
1773
- * because the AOT compiler requires that this information is statically available at
1774
- * compile time.
1775
- *
1776
- * Note that we must do the following:
1777
- * * specify the directive's selector (`ng1-hero`)
1778
- * * specify all inputs and outputs that the AngularJS component expects
1779
- * * derive from `UpgradeComponent`
1780
- * * call the base class from the constructor, passing
1781
- * * the AngularJS name of the component (`ng1Hero`)
1782
- * * the `ElementRef` and `Injector` for the component wrapper
1783
- *
1784
- * @publicApi
1785
- * @extensible
1786
- */
1787
- var UpgradeComponent = /** @class */ (function () {
1788
- /**
1789
- * Create a new `UpgradeComponent` instance. You should not normally need to do this.
1790
- * Instead you should derive a new class from this one and call the super constructor
1791
- * from the base class.
1792
- *
1793
- * {@example upgrade/static/ts/full/module.ts region="ng1-hero-wrapper" }
1794
- *
1795
- * * The `name` parameter should be the name of the AngularJS directive.
1796
- * * The `elementRef` and `injector` parameters should be acquired from Angular by dependency
1797
- * injection into the base class constructor.
1798
- */
1799
- function UpgradeComponent(name, elementRef, injector) {
1800
- this.name = name;
1801
- this.elementRef = elementRef;
1802
- this.injector = injector;
1803
- this.helper = new UpgradeHelper(injector, name, elementRef);
1804
- this.$injector = this.helper.$injector;
1805
- this.element = this.helper.element;
1806
- this.$element = this.helper.$element;
1807
- this.directive = this.helper.directive;
1808
- this.bindings = this.initializeBindings(this.directive);
1809
- // We ask for the AngularJS scope from the Angular injector, since
1810
- // we will put the new component scope onto the new injector for each component
1811
- var $parentScope = injector.get($SCOPE);
1812
- // QUESTION 1: Should we create an isolated scope if the scope is only true?
1813
- // QUESTION 2: Should we make the scope accessible through `$element.scope()/isolateScope()`?
1814
- this.$componentScope = $parentScope.$new(!!this.directive.scope);
1815
- this.initializeOutputs();
1816
- }
1817
- UpgradeComponent.prototype.ngOnInit = function () {
1818
- var _this = this;
1819
- // Collect contents, insert and compile template
1820
- var attachChildNodes = this.helper.prepareTransclusion();
1821
- var linkFn = this.helper.compileTemplate();
1822
- // Instantiate controller
1823
- var controllerType = this.directive.controller;
1824
- var bindToController = this.directive.bindToController;
1825
- if (controllerType) {
1826
- this.controllerInstance = this.helper.buildController(controllerType, this.$componentScope);
1827
- }
1828
- else if (bindToController) {
1829
- throw new Error("Upgraded directive '" + this.directive.name + "' specifies 'bindToController' but no controller.");
1830
- }
1831
- // Set up outputs
1832
- this.bindingDestination = bindToController ? this.controllerInstance : this.$componentScope;
1833
- this.bindOutputs();
1834
- // Require other controllers
1835
- var requiredControllers = this.helper.resolveAndBindRequiredControllers(this.controllerInstance);
1836
- // Hook: $onChanges
1837
- if (this.pendingChanges) {
1838
- this.forwardChanges(this.pendingChanges);
1839
- this.pendingChanges = null;
1840
- }
1841
- // Hook: $onInit
1842
- if (this.controllerInstance && isFunction(this.controllerInstance.$onInit)) {
1843
- this.controllerInstance.$onInit();
1844
- }
1845
- // Hook: $doCheck
1846
- if (this.controllerInstance && isFunction(this.controllerInstance.$doCheck)) {
1847
- var callDoCheck = function () { return _this.controllerInstance.$doCheck(); };
1848
- this.unregisterDoCheckWatcher = this.$componentScope.$parent.$watch(callDoCheck);
1849
- callDoCheck();
1850
- }
1851
- // Linking
1852
- var link = this.directive.link;
1853
- var preLink = typeof link == 'object' && link.pre;
1854
- var postLink = typeof link == 'object' ? link.post : link;
1855
- var attrs = NOT_SUPPORTED;
1856
- var transcludeFn = NOT_SUPPORTED;
1857
- if (preLink) {
1858
- preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
1859
- }
1860
- linkFn(this.$componentScope, null, { parentBoundTranscludeFn: attachChildNodes });
1861
- if (postLink) {
1862
- postLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
1863
- }
1864
- // Hook: $postLink
1865
- if (this.controllerInstance && isFunction(this.controllerInstance.$postLink)) {
1866
- this.controllerInstance.$postLink();
1867
- }
1868
- };
1869
- UpgradeComponent.prototype.ngOnChanges = function (changes) {
1870
- if (!this.bindingDestination) {
1871
- this.pendingChanges = changes;
1872
- }
1873
- else {
1874
- this.forwardChanges(changes);
1875
- }
1876
- };
1877
- UpgradeComponent.prototype.ngDoCheck = function () {
1878
- var _this = this;
1879
- var twoWayBoundProperties = this.bindings.twoWayBoundProperties;
1880
- var twoWayBoundLastValues = this.bindings.twoWayBoundLastValues;
1881
- var propertyToOutputMap = this.bindings.propertyToOutputMap;
1882
- twoWayBoundProperties.forEach(function (propName, idx) {
1883
- var newValue = _this.bindingDestination[propName];
1884
- var oldValue = twoWayBoundLastValues[idx];
1885
- if (!Object.is(newValue, oldValue)) {
1886
- var outputName = propertyToOutputMap[propName];
1887
- var eventEmitter = _this[outputName];
1888
- eventEmitter.emit(newValue);
1889
- twoWayBoundLastValues[idx] = newValue;
1890
- }
1891
- });
1892
- };
1893
- UpgradeComponent.prototype.ngOnDestroy = function () {
1894
- if (isFunction(this.unregisterDoCheckWatcher)) {
1895
- this.unregisterDoCheckWatcher();
1896
- }
1897
- this.helper.onDestroy(this.$componentScope, this.controllerInstance);
1898
- };
1899
- UpgradeComponent.prototype.initializeBindings = function (directive) {
1900
- var _this = this;
1901
- var btcIsObject = typeof directive.bindToController === 'object';
1902
- if (btcIsObject && Object.keys(directive.scope).length) {
1903
- throw new Error("Binding definitions on scope and controller at the same time is not supported.");
1904
- }
1905
- var context = btcIsObject ? directive.bindToController : directive.scope;
1906
- var bindings = new Bindings();
1907
- if (typeof context == 'object') {
1908
- Object.keys(context).forEach(function (propName) {
1909
- var definition = context[propName];
1910
- var bindingType = definition.charAt(0);
1911
- // QUESTION: What about `=*`? Ignore? Throw? Support?
1912
- switch (bindingType) {
1913
- case '@':
1914
- case '<':
1915
- // We don't need to do anything special. They will be defined as inputs on the
1916
- // upgraded component facade and the change propagation will be handled by
1917
- // `ngOnChanges()`.
1918
- break;
1919
- case '=':
1920
- bindings.twoWayBoundProperties.push(propName);
1921
- bindings.twoWayBoundLastValues.push(INITIAL_VALUE$1);
1922
- bindings.propertyToOutputMap[propName] = propName + 'Change';
1923
- break;
1924
- case '&':
1925
- bindings.expressionBoundProperties.push(propName);
1926
- bindings.propertyToOutputMap[propName] = propName;
1927
- break;
1928
- default:
1929
- var json = JSON.stringify(context);
1930
- throw new Error("Unexpected mapping '" + bindingType + "' in '" + json + "' in '" + _this.name + "' directive.");
1931
- }
1932
- });
1933
- }
1934
- return bindings;
1935
- };
1936
- UpgradeComponent.prototype.initializeOutputs = function () {
1937
- var _this = this;
1938
- // Initialize the outputs for `=` and `&` bindings
1939
- this.bindings.twoWayBoundProperties.concat(this.bindings.expressionBoundProperties)
1940
- .forEach(function (propName) {
1941
- var outputName = _this.bindings.propertyToOutputMap[propName];
1942
- _this[outputName] = new core.EventEmitter();
1943
- });
1944
- };
1945
- UpgradeComponent.prototype.bindOutputs = function () {
1946
- var _this = this;
1947
- // Bind `&` bindings to the corresponding outputs
1948
- this.bindings.expressionBoundProperties.forEach(function (propName) {
1949
- var outputName = _this.bindings.propertyToOutputMap[propName];
1950
- var emitter = _this[outputName];
1951
- _this.bindingDestination[propName] = function (value) { return emitter.emit(value); };
1952
- });
1953
- };
1954
- UpgradeComponent.prototype.forwardChanges = function (changes) {
1955
- var _this = this;
1956
- // Forward input changes to `bindingDestination`
1957
- Object.keys(changes).forEach(function (propName) { return _this.bindingDestination[propName] = changes[propName].currentValue; });
1958
- if (isFunction(this.bindingDestination.$onChanges)) {
1959
- this.bindingDestination.$onChanges(changes);
1960
- }
1961
- };
1962
- return UpgradeComponent;
1963
- }());
1964
- UpgradeComponent.decorators = [
1965
- { type: core.Directive }
1966
- ];
1967
- UpgradeComponent.ctorParameters = function () { return [
1968
- { type: String },
1969
- { type: core.ElementRef },
1970
- { type: core.Injector }
1971
- ]; };
1972
-
1973
- /**
1974
- * @description
1975
- *
1976
- * An `NgModule`, which you import to provide AngularJS core services,
1977
- * and has an instance method used to bootstrap the hybrid upgrade application.
1978
- *
1979
- * *Part of the [upgrade/static](api?query=upgrade/static)
1980
- * library for hybrid upgrade apps that support AOT compilation*
1981
- *
1982
- * The `upgrade/static` package contains helpers that allow AngularJS and Angular components
1983
- * to be used together inside a hybrid upgrade application, which supports AOT compilation.
1984
- *
1985
- * Specifically, the classes and functions in the `upgrade/static` module allow the following:
1986
- *
1987
- * 1. Creation of an Angular directive that wraps and exposes an AngularJS component so
1988
- * that it can be used in an Angular template. See `UpgradeComponent`.
1989
- * 2. Creation of an AngularJS directive that wraps and exposes an Angular component so
1990
- * that it can be used in an AngularJS template. See `downgradeComponent`.
1991
- * 3. Creation of an Angular root injector provider that wraps and exposes an AngularJS
1992
- * service so that it can be injected into an Angular context. See
1993
- * {@link UpgradeModule#upgrading-an-angular-1-service Upgrading an AngularJS service} below.
1994
- * 4. Creation of an AngularJS service that wraps and exposes an Angular injectable
1995
- * so that it can be injected into an AngularJS context. See `downgradeInjectable`.
1996
- * 3. Bootstrapping of a hybrid Angular application which contains both of the frameworks
1997
- * coexisting in a single application.
1998
- *
1999
- * @usageNotes
2000
- *
2001
- * ```ts
2002
- * import {UpgradeModule} from '@angular/upgrade/static';
2003
- * ```
2004
- *
2005
- * See also the {@link UpgradeModule#examples examples} below.
2006
- *
2007
- * ### Mental Model
2008
- *
2009
- * When reasoning about how a hybrid application works it is useful to have a mental model which
2010
- * describes what is happening and explains what is happening at the lowest level.
2011
- *
2012
- * 1. There are two independent frameworks running in a single application, each framework treats
2013
- * the other as a black box.
2014
- * 2. Each DOM element on the page is owned exactly by one framework. Whichever framework
2015
- * instantiated the element is the owner. Each framework only updates/interacts with its own
2016
- * DOM elements and ignores others.
2017
- * 3. AngularJS directives always execute inside the AngularJS framework codebase regardless of
2018
- * where they are instantiated.
2019
- * 4. Angular components always execute inside the Angular framework codebase regardless of
2020
- * where they are instantiated.
2021
- * 5. An AngularJS component can be "upgraded"" to an Angular component. This is achieved by
2022
- * defining an Angular directive, which bootstraps the AngularJS component at its location
2023
- * in the DOM. See `UpgradeComponent`.
2024
- * 6. An Angular component can be "downgraded" to an AngularJS component. This is achieved by
2025
- * defining an AngularJS directive, which bootstraps the Angular component at its location
2026
- * in the DOM. See `downgradeComponent`.
2027
- * 7. Whenever an "upgraded"/"downgraded" component is instantiated the host element is owned by
2028
- * the framework doing the instantiation. The other framework then instantiates and owns the
2029
- * view for that component.
2030
- * 1. This implies that the component bindings will always follow the semantics of the
2031
- * instantiation framework.
2032
- * 2. The DOM attributes are parsed by the framework that owns the current template. So
2033
- * attributes in AngularJS templates must use kebab-case, while AngularJS templates must use
2034
- * camelCase.
2035
- * 3. However the template binding syntax will always use the Angular style, e.g. square
2036
- * brackets (`[...]`) for property binding.
2037
- * 8. Angular is bootstrapped first; AngularJS is bootstrapped second. AngularJS always owns the
2038
- * root component of the application.
2039
- * 9. The new application is running in an Angular zone, and therefore it no longer needs calls to
2040
- * `$apply()`.
2041
- *
2042
- * ### The `UpgradeModule` class
2043
- *
2044
- * This class is an `NgModule`, which you import to provide AngularJS core services,
2045
- * and has an instance method used to bootstrap the hybrid upgrade application.
2046
- *
2047
- * * Core AngularJS services
2048
- * Importing this `NgModule` will add providers for the core
2049
- * [AngularJS services](https://docs.angularjs.org/api/ng/service) to the root injector.
2050
- *
2051
- * * Bootstrap
2052
- * The runtime instance of this class contains a {@link UpgradeModule#bootstrap `bootstrap()`}
2053
- * method, which you use to bootstrap the top level AngularJS module onto an element in the
2054
- * DOM for the hybrid upgrade app.
2055
- *
2056
- * It also contains properties to access the {@link UpgradeModule#injector root injector}, the
2057
- * bootstrap `NgZone` and the
2058
- * [AngularJS $injector](https://docs.angularjs.org/api/auto/service/$injector).
2059
- *
2060
- * ### Examples
2061
- *
2062
- * Import the `UpgradeModule` into your top level {@link NgModule Angular `NgModule`}.
2063
- *
2064
- * {@example upgrade/static/ts/full/module.ts region='ng2-module'}
2065
- *
2066
- * Then inject `UpgradeModule` into your Angular `NgModule` and use it to bootstrap the top level
2067
- * [AngularJS module](https://docs.angularjs.org/api/ng/type/angular.Module) in the
2068
- * `ngDoBootstrap()` method.
2069
- *
2070
- * {@example upgrade/static/ts/full/module.ts region='bootstrap-ng1'}
2071
- *
2072
- * Finally, kick off the whole process, by bootstrapping your top level Angular `NgModule`.
2073
- *
2074
- * {@example upgrade/static/ts/full/module.ts region='bootstrap-ng2'}
2075
- *
2076
- * {@a upgrading-an-angular-1-service}
2077
- * ### Upgrading an AngularJS service
2078
- *
2079
- * There is no specific API for upgrading an AngularJS service. Instead you should just follow the
2080
- * following recipe:
2081
- *
2082
- * Let's say you have an AngularJS service:
2083
- *
2084
- * {@example upgrade/static/ts/full/module.ts region="ng1-text-formatter-service"}
2085
- *
2086
- * Then you should define an Angular provider to be included in your `NgModule` `providers`
2087
- * property.
2088
- *
2089
- * {@example upgrade/static/ts/full/module.ts region="upgrade-ng1-service"}
2090
- *
2091
- * Then you can use the "upgraded" AngularJS service by injecting it into an Angular component
2092
- * or service.
2093
- *
2094
- * {@example upgrade/static/ts/full/module.ts region="use-ng1-upgraded-service"}
2095
- *
2096
- * @publicApi
2097
- */
2098
- var UpgradeModule = /** @class */ (function () {
2099
- function UpgradeModule(
2100
- /** The root `Injector` for the upgrade application. */
2101
- injector,
2102
- /** The bootstrap zone for the upgrade application */
2103
- ngZone,
2104
- /**
2105
- * The owning `NgModuleRef`s `PlatformRef` instance.
2106
- * This is used to tie the lifecycle of the bootstrapped AngularJS apps to that of the Angular
2107
- * `PlatformRef`.
2108
- */
2109
- platformRef) {
2110
- this.ngZone = ngZone;
2111
- this.platformRef = platformRef;
2112
- this.injector = new NgAdapterInjector(injector);
2113
- }
2114
- /**
2115
- * Bootstrap an AngularJS application from this NgModule
2116
- * @param element the element on which to bootstrap the AngularJS application
2117
- * @param [modules] the AngularJS modules to bootstrap for this application
2118
- * @param [config] optional extra AngularJS bootstrap configuration
2119
- */
2120
- UpgradeModule.prototype.bootstrap = function (element$1, modules, config /*angular.IAngularBootstrapConfig*/) {
2121
- var _this = this;
2122
- if (modules === void 0) { modules = []; }
2123
- var INIT_MODULE_NAME = UPGRADE_MODULE_NAME + '.init';
2124
- // Create an ng1 module to bootstrap
2125
- module_(INIT_MODULE_NAME, [])
2126
- .constant(UPGRADE_APP_TYPE_KEY, 2 /* Static */)
2127
- .value(INJECTOR_KEY, this.injector)
2128
- .factory(LAZY_MODULE_REF, [INJECTOR_KEY, function (injector) { return ({ injector: injector }); }])
2129
- .config([
2130
- $PROVIDE, $INJECTOR,
2131
- function ($provide, $injector) {
2132
- if ($injector.has($$TESTABILITY)) {
2133
- $provide.decorator($$TESTABILITY, [
2134
- $DELEGATE,
2135
- function (testabilityDelegate) {
2136
- var originalWhenStable = testabilityDelegate.whenStable;
2137
- var injector = _this.injector;
2138
- // Cannot use arrow function below because we need the context
2139
- var newWhenStable = function (callback) {
2140
- originalWhenStable.call(testabilityDelegate, function () {
2141
- var ng2Testability = injector.get(core.Testability);
2142
- if (ng2Testability.isStable()) {
2143
- callback();
2144
- }
2145
- else {
2146
- ng2Testability.whenStable(newWhenStable.bind(testabilityDelegate, callback));
2147
- }
2148
- });
2149
- };
2150
- testabilityDelegate.whenStable = newWhenStable;
2151
- return testabilityDelegate;
2152
- }
2153
- ]);
2154
- }
2155
- if ($injector.has($INTERVAL)) {
2156
- $provide.decorator($INTERVAL, [
2157
- $DELEGATE,
2158
- function (intervalDelegate) {
2159
- // Wrap the $interval service so that setInterval is called outside NgZone,
2160
- // but the callback is still invoked within it. This is so that $interval
2161
- // won't block stability, which preserves the behavior from AngularJS.
2162
- var wrappedInterval = function (fn, delay, count, invokeApply) {
2163
- var pass = [];
2164
- for (var _i = 4; _i < arguments.length; _i++) {
2165
- pass[_i - 4] = arguments[_i];
2166
- }
2167
- return _this.ngZone.runOutsideAngular(function () {
2168
- return intervalDelegate.apply(void 0, __spreadArray([function () {
2169
- var args = [];
2170
- for (var _i = 0; _i < arguments.length; _i++) {
2171
- args[_i] = arguments[_i];
2172
- }
2173
- // Run callback in the next VM turn - $interval calls
2174
- // $rootScope.$apply, and running the callback in NgZone will
2175
- // cause a '$digest already in progress' error if it's in the
2176
- // same vm turn.
2177
- setTimeout(function () {
2178
- _this.ngZone.run(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
2179
- });
2180
- }, delay, count, invokeApply], __read(pass), false));
2181
- });
2182
- };
2183
- Object.keys(intervalDelegate)
2184
- .forEach(function (prop) { return wrappedInterval[prop] = intervalDelegate[prop]; });
2185
- // the `flush` method will be present when ngMocks is used
2186
- if (intervalDelegate.hasOwnProperty('flush')) {
2187
- wrappedInterval['flush'] = function () {
2188
- intervalDelegate['flush']();
2189
- return wrappedInterval;
2190
- };
2191
- }
2192
- return wrappedInterval;
2193
- }
2194
- ]);
2195
- }
2196
- }
2197
- ])
2198
- .run([
2199
- $INJECTOR,
2200
- function ($injector) {
2201
- _this.$injector = $injector;
2202
- var $rootScope = $injector.get('$rootScope');
2203
- // Initialize the ng1 $injector provider
2204
- setTempInjectorRef($injector);
2205
- _this.injector.get($INJECTOR);
2206
- // Put the injector on the DOM, so that it can be "required"
2207
- element(element$1).data(controllerKey(INJECTOR_KEY), _this.injector);
2208
- // Destroy the AngularJS app once the Angular `PlatformRef` is destroyed.
2209
- // This does not happen in a typical SPA scenario, but it might be useful for
2210
- // other use-cases where disposing of an Angular/AngularJS app is necessary
2211
- // (such as Hot Module Replacement (HMR)).
2212
- // See https://github.com/angular/angular/issues/39935.
2213
- _this.platformRef.onDestroy(function () { return destroyApp($injector); });
2214
- // Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
2215
- // We need to do this in the next tick so that we don't prevent the bootup stabilizing
2216
- setTimeout(function () {
2217
- var subscription = _this.ngZone.onMicrotaskEmpty.subscribe(function () {
2218
- if ($rootScope.$$phase) {
2219
- if (core.isDevMode()) {
2220
- console.warn('A digest was triggered while one was already in progress. This may mean that something is triggering digests outside the Angular zone.');
2221
- }
2222
- return $rootScope.$evalAsync();
2223
- }
2224
- return $rootScope.$digest();
2225
- });
2226
- $rootScope.$on('$destroy', function () {
2227
- subscription.unsubscribe();
2228
- });
2229
- }, 0);
2230
- }
2231
- ]);
2232
- var upgradeModule = module_(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
2233
- // Make sure resumeBootstrap() only exists if the current bootstrap is deferred
2234
- var windowAngular = window['angular'];
2235
- windowAngular.resumeBootstrap = undefined;
2236
- // Bootstrap the AngularJS application inside our zone
2237
- this.ngZone.run(function () {
2238
- bootstrap(element$1, [upgradeModule.name], config);
2239
- });
2240
- // Patch resumeBootstrap() to run inside the ngZone
2241
- if (windowAngular.resumeBootstrap) {
2242
- var originalResumeBootstrap_1 = windowAngular.resumeBootstrap;
2243
- var ngZone_1 = this.ngZone;
2244
- windowAngular.resumeBootstrap = function () {
2245
- var _this = this;
2246
- var args = arguments;
2247
- windowAngular.resumeBootstrap = originalResumeBootstrap_1;
2248
- return ngZone_1.run(function () { return windowAngular.resumeBootstrap.apply(_this, args); });
2249
- };
2250
- }
2251
- };
2252
- return UpgradeModule;
2253
- }());
2254
- UpgradeModule.decorators = [
2255
- { type: core.NgModule, args: [{ providers: [angular1Providers] },] }
2256
- ];
2257
- UpgradeModule.ctorParameters = function () { return [
2258
- { type: core.Injector },
2259
- { type: core.NgZone },
2260
- { type: core.PlatformRef }
2261
- ]; };
2262
-
2263
- /**
2264
- * @license
2265
- * Copyright Google LLC All Rights Reserved.
2266
- *
2267
- * Use of this source code is governed by an MIT-style license that can be
2268
- * found in the LICENSE file at https://angular.io/license
2269
- */
2270
- // This file only re-exports items to appear in the public api. Keep it that way.
2271
-
2272
- /**
2273
- * @license
2274
- * Copyright Google LLC All Rights Reserved.
2275
- *
2276
- * Use of this source code is governed by an MIT-style license that can be
2277
- * found in the LICENSE file at https://angular.io/license
2278
- */
2279
-
2280
- /**
2281
- * Generated bundle index. Do not edit.
2282
- */
2283
-
2284
- exports.UpgradeComponent = UpgradeComponent;
2285
- exports.UpgradeModule = UpgradeModule;
2286
- exports.VERSION = VERSION;
2287
- exports.downgradeComponent = downgradeComponent;
2288
- exports.downgradeInjectable = downgradeInjectable;
2289
- exports.downgradeModule = downgradeModule;
2290
- exports.getAngularJSGlobal = getAngularJSGlobal;
2291
- exports.getAngularLib = getAngularLib;
2292
- exports.setAngularJSGlobal = setAngularJSGlobal;
2293
- exports.setAngularLib = setAngularLib;
2294
- exports.ɵangular_packages_upgrade_static_static_a = injectorFactory;
2295
- exports.ɵangular_packages_upgrade_static_static_b = rootScopeFactory;
2296
- exports.ɵangular_packages_upgrade_static_static_c = compileFactory;
2297
- exports.ɵangular_packages_upgrade_static_static_d = parseFactory;
2298
- exports.ɵangular_packages_upgrade_static_static_e = angular1Providers;
2299
-
2300
- Object.defineProperty(exports, '__esModule', { value: true });
2301
-
2302
- })));
2303
- //# sourceMappingURL=upgrade-static.umd.js.map