UNPKG

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