refactor: replace local namespaced imports with named (#28642)
At the moment, the API extractor doesn't support local namespaced imports, this will break the generation of flat dts files. When we turn on dts bundling for this package it will break. Hence this is the ground work needed for making this package compatable with the API extractor. See: https://github.com/Microsoft/web-build-tools/issues/1029 Relates to #28588 PR Close #28642
This commit is contained in:
parent
599e2e22bc
commit
7c1b9ff5ec
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {ComponentFactory, ComponentFactoryResolver, Injector, NgZone, Type} from '@angular/core';
|
import {ComponentFactory, ComponentFactoryResolver, Injector, NgZone, Type} from '@angular/core';
|
||||||
|
|
||||||
import * as angular from './angular1';
|
import {IAnnotatedFunction, IAttributes, IAugmentedJQuery, ICompileService, IDirective, IInjectorService, INgModelController, IParseService, IScope} from './angular1';
|
||||||
import {$COMPILE, $INJECTOR, $PARSE, INJECTOR_KEY, LAZY_MODULE_REF, REQUIRE_INJECTOR, REQUIRE_NG_MODEL} from './constants';
|
import {$COMPILE, $INJECTOR, $PARSE, INJECTOR_KEY, LAZY_MODULE_REF, REQUIRE_INJECTOR, REQUIRE_NG_MODEL} from './constants';
|
||||||
import {DowngradeComponentAdapter} from './downgrade_component_adapter';
|
import {DowngradeComponentAdapter} from './downgrade_component_adapter';
|
||||||
import {LazyModuleRef, UpgradeAppType, controllerKey, getDowngradedModuleCount, getTypeName, getUpgradeAppType, isFunction, validateInjectionKey} from './util';
|
import {LazyModuleRef, UpgradeAppType, controllerKey, getDowngradedModuleCount, getTypeName, getUpgradeAppType, isFunction, validateInjectionKey} from './util';
|
||||||
|
@ -73,11 +73,8 @@ export function downgradeComponent(info: {
|
||||||
/** @deprecated since v4. This parameter is no longer used */
|
/** @deprecated since v4. This parameter is no longer used */
|
||||||
selectors?: string[];
|
selectors?: string[];
|
||||||
}): any /* angular.IInjectable */ {
|
}): any /* angular.IInjectable */ {
|
||||||
const directiveFactory:
|
const directiveFactory: IAnnotatedFunction = function(
|
||||||
angular.IAnnotatedFunction = function(
|
$compile: ICompileService, $injector: IInjectorService, $parse: IParseService): IDirective {
|
||||||
$compile: angular.ICompileService,
|
|
||||||
$injector: angular.IInjectorService,
|
|
||||||
$parse: angular.IParseService): angular.IDirective {
|
|
||||||
// When using `downgradeModule()`, we need to handle certain things specially. For example:
|
// When using `downgradeModule()`, we need to handle certain things specially. For example:
|
||||||
// - We always need to attach the component view to the `ApplicationRef` for it to be
|
// - We always need to attach the component view to the `ApplicationRef` for it to be
|
||||||
// dirty-checked.
|
// dirty-checked.
|
||||||
|
@ -99,13 +96,12 @@ export function downgradeComponent(info: {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
terminal: true,
|
terminal: true,
|
||||||
require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
|
require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
|
||||||
link: (scope: angular.IScope, element: angular.IAugmentedJQuery, attrs: angular.IAttributes,
|
link: (scope: IScope, element: IAugmentedJQuery, attrs: IAttributes, required: any[]) => {
|
||||||
required: any[]) => {
|
|
||||||
// We might have to compile the contents asynchronously, because this might have been
|
// We might have to compile the contents asynchronously, because this might have been
|
||||||
// triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have
|
// triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have
|
||||||
// been compiled.
|
// been compiled.
|
||||||
|
|
||||||
const ngModel: angular.INgModelController = required[1];
|
const ngModel: INgModelController = required[1];
|
||||||
const parentInjector: Injector|Thenable<Injector>|undefined = required[0];
|
const parentInjector: Injector|Thenable<Injector>|undefined = required[0];
|
||||||
let moduleInjector: Injector|Thenable<Injector>|undefined = undefined;
|
let moduleInjector: Injector|Thenable<Injector>|undefined = undefined;
|
||||||
let ranAsync = false;
|
let ranAsync = false;
|
||||||
|
@ -230,7 +226,7 @@ class ParentInjectorPromise {
|
||||||
private injectorKey: string = controllerKey(INJECTOR_KEY);
|
private injectorKey: string = controllerKey(INJECTOR_KEY);
|
||||||
private callbacks: ((injector: Injector) => any)[] = [];
|
private callbacks: ((injector: Injector) => any)[] = [];
|
||||||
|
|
||||||
constructor(private element: angular.IAugmentedJQuery) {
|
constructor(private element: IAugmentedJQuery) {
|
||||||
// Store the promise on the element.
|
// Store the promise on the element.
|
||||||
element.data !(this.injectorKey, this);
|
element.data !(this.injectorKey, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {ApplicationRef, ChangeDetectorRef, ComponentFactory, ComponentRef, EventEmitter, Injector, OnChanges, SimpleChange, SimpleChanges, StaticProvider, Testability, TestabilityRegistry, Type} from '@angular/core';
|
import {ApplicationRef, ChangeDetectorRef, ComponentFactory, ComponentRef, EventEmitter, Injector, OnChanges, SimpleChange, SimpleChanges, StaticProvider, Testability, TestabilityRegistry, Type} from '@angular/core';
|
||||||
|
|
||||||
import * as angular from './angular1';
|
import {IAttributes, IAugmentedJQuery, ICompileService, IInjectorService, INgModelController, IParseService, IScope} from './angular1';
|
||||||
import {PropertyBinding} from './component_info';
|
import {PropertyBinding} from './component_info';
|
||||||
import {$SCOPE} from './constants';
|
import {$SCOPE} from './constants';
|
||||||
import {getTypeName, hookupNgModel, strictEquals} from './util';
|
import {getTypeName, hookupNgModel, strictEquals} from './util';
|
||||||
|
@ -21,7 +21,7 @@ export class DowngradeComponentAdapter {
|
||||||
private implementsOnChanges = false;
|
private implementsOnChanges = false;
|
||||||
private inputChangeCount: number = 0;
|
private inputChangeCount: number = 0;
|
||||||
private inputChanges: SimpleChanges = {};
|
private inputChanges: SimpleChanges = {};
|
||||||
private componentScope: angular.IScope;
|
private componentScope: IScope;
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
private componentRef !: ComponentRef<any>;
|
private componentRef !: ComponentRef<any>;
|
||||||
private component: any;
|
private component: any;
|
||||||
|
@ -31,11 +31,10 @@ export class DowngradeComponentAdapter {
|
||||||
private viewChangeDetector !: ChangeDetectorRef;
|
private viewChangeDetector !: ChangeDetectorRef;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private element: angular.IAugmentedJQuery, private attrs: angular.IAttributes,
|
private element: IAugmentedJQuery, private attrs: IAttributes, private scope: IScope,
|
||||||
private scope: angular.IScope, private ngModel: angular.INgModelController,
|
private ngModel: INgModelController, private parentInjector: Injector,
|
||||||
private parentInjector: Injector, private $injector: angular.IInjectorService,
|
private $injector: IInjectorService, private $compile: ICompileService,
|
||||||
private $compile: angular.ICompileService, private $parse: angular.IParseService,
|
private $parse: IParseService, private componentFactory: ComponentFactory<any>,
|
||||||
private componentFactory: ComponentFactory<any>,
|
|
||||||
private wrapCallback: <T>(cb: () => T) => () => T) {
|
private wrapCallback: <T>(cb: () => T) => () => T) {
|
||||||
this.componentScope = scope.$new();
|
this.componentScope = scope.$new();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injector} from '@angular/core';
|
import {Injector} from '@angular/core';
|
||||||
import * as angular from './angular1';
|
import {IInjectorService} from './angular1';
|
||||||
import {$INJECTOR, INJECTOR_KEY} from './constants';
|
import {$INJECTOR, INJECTOR_KEY} from './constants';
|
||||||
import {getTypeName, isFunction, validateInjectionKey} from './util';
|
import {getTypeName, isFunction, validateInjectionKey} from './util';
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ import {getTypeName, isFunction, validateInjectionKey} from './util';
|
||||||
* @publicApi
|
* @publicApi
|
||||||
*/
|
*/
|
||||||
export function downgradeInjectable(token: any, downgradedModule: string = ''): Function {
|
export function downgradeInjectable(token: any, downgradedModule: string = ''): Function {
|
||||||
const factory = function($injector: angular.IInjectorService) {
|
const factory = function($injector: IInjectorService) {
|
||||||
const injectorKey = `${INJECTOR_KEY}${downgradedModule}`;
|
const injectorKey = `${INJECTOR_KEY}${downgradedModule}`;
|
||||||
const injectableName = isFunction(token) ? getTypeName(token) : String(token);
|
const injectableName = isFunction(token) ? getTypeName(token) : String(token);
|
||||||
const attemptedAction = `instantiating injectable '${injectableName}'`;
|
const attemptedAction = `instantiating injectable '${injectableName}'`;
|
||||||
|
|
|
@ -8,11 +8,12 @@
|
||||||
|
|
||||||
import {ElementRef, Injector, SimpleChanges} from '@angular/core';
|
import {ElementRef, Injector, SimpleChanges} from '@angular/core';
|
||||||
|
|
||||||
import * as angular from './angular1';
|
import {DirectiveRequireProperty, IAugmentedJQuery, ICloneAttachFunction, ICompileService, IController, IControllerService, IDirective, IHttpBackendService, IInjectorService, ILinkFn, IScope, ITemplateCacheService, SingleOrListOrMap, element as angularElement} from './angular1';
|
||||||
import {$COMPILE, $CONTROLLER, $HTTP_BACKEND, $INJECTOR, $TEMPLATE_CACHE} from './constants';
|
import {$COMPILE, $CONTROLLER, $HTTP_BACKEND, $INJECTOR, $TEMPLATE_CACHE} from './constants';
|
||||||
import {controllerKey, directiveNormalize, isFunction} from './util';
|
import {controllerKey, directiveNormalize, isFunction} from './util';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
|
const REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
|
||||||
|
|
||||||
|
@ -31,29 +32,29 @@ export interface IControllerInstance extends IBindingDestination {
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
export class UpgradeHelper {
|
export class UpgradeHelper {
|
||||||
public readonly $injector: angular.IInjectorService;
|
public readonly $injector: IInjectorService;
|
||||||
public readonly element: Element;
|
public readonly element: Element;
|
||||||
public readonly $element: angular.IAugmentedJQuery;
|
public readonly $element: IAugmentedJQuery;
|
||||||
public readonly directive: angular.IDirective;
|
public readonly directive: IDirective;
|
||||||
|
|
||||||
private readonly $compile: angular.ICompileService;
|
private readonly $compile: ICompileService;
|
||||||
private readonly $controller: angular.IControllerService;
|
private readonly $controller: IControllerService;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private injector: Injector, private name: string, elementRef: ElementRef,
|
private injector: Injector, private name: string, elementRef: ElementRef,
|
||||||
directive?: angular.IDirective) {
|
directive?: IDirective) {
|
||||||
this.$injector = injector.get($INJECTOR);
|
this.$injector = injector.get($INJECTOR);
|
||||||
this.$compile = this.$injector.get($COMPILE);
|
this.$compile = this.$injector.get($COMPILE);
|
||||||
this.$controller = this.$injector.get($CONTROLLER);
|
this.$controller = this.$injector.get($CONTROLLER);
|
||||||
|
|
||||||
this.element = elementRef.nativeElement;
|
this.element = elementRef.nativeElement;
|
||||||
this.$element = angular.element(this.element);
|
this.$element = angularElement(this.element);
|
||||||
|
|
||||||
this.directive = directive || UpgradeHelper.getDirective(this.$injector, name);
|
this.directive = directive || UpgradeHelper.getDirective(this.$injector, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDirective($injector: angular.IInjectorService, name: string): angular.IDirective {
|
static getDirective($injector: IInjectorService, name: string): IDirective {
|
||||||
const directives: angular.IDirective[] = $injector.get(name + 'Directive');
|
const directives: IDirective[] = $injector.get(name + 'Directive');
|
||||||
if (directives.length > 1) {
|
if (directives.length > 1) {
|
||||||
throw new Error(`Only support single directive definition for: ${name}`);
|
throw new Error(`Only support single directive definition for: ${name}`);
|
||||||
}
|
}
|
||||||
|
@ -70,12 +71,12 @@ export class UpgradeHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static getTemplate(
|
static getTemplate(
|
||||||
$injector: angular.IInjectorService, directive: angular.IDirective,
|
$injector: IInjectorService, directive: IDirective, fetchRemoteTemplate = false): string
|
||||||
fetchRemoteTemplate = false): string|Promise<string> {
|
|Promise<string> {
|
||||||
if (directive.template !== undefined) {
|
if (directive.template !== undefined) {
|
||||||
return getOrCall<string>(directive.template);
|
return getOrCall<string>(directive.template);
|
||||||
} else if (directive.templateUrl) {
|
} else if (directive.templateUrl) {
|
||||||
const $templateCache = $injector.get($TEMPLATE_CACHE) as angular.ITemplateCacheService;
|
const $templateCache = $injector.get($TEMPLATE_CACHE) as ITemplateCacheService;
|
||||||
const url = getOrCall<string>(directive.templateUrl);
|
const url = getOrCall<string>(directive.templateUrl);
|
||||||
const template = $templateCache.get(url);
|
const template = $templateCache.get(url);
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ export class UpgradeHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const $httpBackend = $injector.get($HTTP_BACKEND) as angular.IHttpBackendService;
|
const $httpBackend = $injector.get($HTTP_BACKEND) as IHttpBackendService;
|
||||||
$httpBackend('GET', url, null, (status: number, response: string) => {
|
$httpBackend('GET', url, null, (status: number, response: string) => {
|
||||||
if (status === 200) {
|
if (status === 200) {
|
||||||
resolve($templateCache.put(url, response));
|
resolve($templateCache.put(url, response));
|
||||||
|
@ -100,7 +101,7 @@ export class UpgradeHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildController(controllerType: angular.IController, $scope: angular.IScope) {
|
buildController(controllerType: IController, $scope: IScope) {
|
||||||
// TODO: Document that we do not pre-assign bindings on the controller instance.
|
// TODO: Document that we do not pre-assign bindings on the controller instance.
|
||||||
// Quoted properties below so that this code can be optimized with Closure Compiler.
|
// Quoted properties below so that this code can be optimized with Closure Compiler.
|
||||||
const locals = {'$scope': $scope, '$element': this.$element};
|
const locals = {'$scope': $scope, '$element': this.$element};
|
||||||
|
@ -111,7 +112,7 @@ export class UpgradeHelper {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTemplate(template?: string): angular.ILinkFn {
|
compileTemplate(template?: string): ILinkFn {
|
||||||
if (template === undefined) {
|
if (template === undefined) {
|
||||||
template = UpgradeHelper.getTemplate(this.$injector, this.directive) as string;
|
template = UpgradeHelper.getTemplate(this.$injector, this.directive) as string;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +120,7 @@ export class UpgradeHelper {
|
||||||
return this.compileHtml(template);
|
return this.compileHtml(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy($scope: angular.IScope, controllerInstance?: any) {
|
onDestroy($scope: IScope, controllerInstance?: any) {
|
||||||
if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
|
if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
|
||||||
controllerInstance.$onDestroy();
|
controllerInstance.$onDestroy();
|
||||||
}
|
}
|
||||||
|
@ -131,14 +132,14 @@ export class UpgradeHelper {
|
||||||
// https://github.com/angular/angular.js/blob/26ddc5f830f902a3d22f4b2aab70d86d4d688c82/src/jqLite.js#L306-L312
|
// https://github.com/angular/angular.js/blob/26ddc5f830f902a3d22f4b2aab70d86d4d688c82/src/jqLite.js#L306-L312
|
||||||
// `cleanData` will invoke the AngularJS `$destroy` DOM event
|
// `cleanData` will invoke the AngularJS `$destroy` DOM event
|
||||||
// https://github.com/angular/angular.js/blob/26ddc5f830f902a3d22f4b2aab70d86d4d688c82/src/Angular.js#L1911-L1924
|
// https://github.com/angular/angular.js/blob/26ddc5f830f902a3d22f4b2aab70d86d4d688c82/src/Angular.js#L1911-L1924
|
||||||
angular.element.cleanData([this.element]);
|
angularElement.cleanData([this.element]);
|
||||||
angular.element.cleanData(this.element.querySelectorAll('*'));
|
angularElement.cleanData(this.element.querySelectorAll('*'));
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareTransclusion(): angular.ILinkFn|undefined {
|
prepareTransclusion(): ILinkFn|undefined {
|
||||||
const transclude = this.directive.transclude;
|
const transclude = this.directive.transclude;
|
||||||
const contentChildNodes = this.extractChildNodes();
|
const contentChildNodes = this.extractChildNodes();
|
||||||
const attachChildrenFn: angular.ILinkFn = (scope, cloneAttachFn) => {
|
const attachChildrenFn: ILinkFn = (scope, cloneAttachFn) => {
|
||||||
// Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
|
// Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
|
||||||
// `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
|
// `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
|
||||||
// there will be no transclusion scope here.
|
// there will be no transclusion scope here.
|
||||||
|
@ -189,8 +190,9 @@ export class UpgradeHelper {
|
||||||
|
|
||||||
Object.keys(slots).filter(slotName => slots[slotName]).forEach(slotName => {
|
Object.keys(slots).filter(slotName => slots[slotName]).forEach(slotName => {
|
||||||
const nodes = slots[slotName];
|
const nodes = slots[slotName];
|
||||||
slots[slotName] = (scope: angular.IScope, cloneAttach: angular.ICloneAttachFunction) =>
|
slots[slotName] = (scope: IScope, cloneAttach: ICloneAttachFunction) => {
|
||||||
cloneAttach !(nodes, scope);
|
return cloneAttach !(nodes, scope);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +233,7 @@ export class UpgradeHelper {
|
||||||
return requiredControllers;
|
return requiredControllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private compileHtml(html: string): angular.ILinkFn {
|
private compileHtml(html: string): ILinkFn {
|
||||||
this.element.innerHTML = html;
|
this.element.innerHTML = html;
|
||||||
return this.$compile(this.element.childNodes);
|
return this.$compile(this.element.childNodes);
|
||||||
}
|
}
|
||||||
|
@ -248,7 +250,7 @@ export class UpgradeHelper {
|
||||||
return childNodes;
|
return childNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getDirectiveRequire(): angular.DirectiveRequireProperty {
|
private getDirectiveRequire(): DirectiveRequireProperty {
|
||||||
const require = this.directive.require || (this.directive.controller && this.directive.name) !;
|
const require = this.directive.require || (this.directive.controller && this.directive.name) !;
|
||||||
|
|
||||||
if (isMap(require)) {
|
if (isMap(require)) {
|
||||||
|
@ -266,8 +268,8 @@ export class UpgradeHelper {
|
||||||
return require;
|
return require;
|
||||||
}
|
}
|
||||||
|
|
||||||
private resolveRequire(require: angular.DirectiveRequireProperty, controllerInstance?: any):
|
private resolveRequire(require: DirectiveRequireProperty, controllerInstance?: any):
|
||||||
angular.SingleOrListOrMap<IControllerInstance>|null {
|
SingleOrListOrMap<IControllerInstance>|null {
|
||||||
if (!require) {
|
if (!require) {
|
||||||
return null;
|
return null;
|
||||||
} else if (Array.isArray(require)) {
|
} else if (Array.isArray(require)) {
|
||||||
|
@ -307,7 +309,7 @@ function getOrCall<T>(property: T | Function): T {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Only works for `typeof T !== 'object'`.
|
// NOTE: Only works for `typeof T !== 'object'`.
|
||||||
function isMap<T>(value: angular.SingleOrListOrMap<T>): value is {[key: string]: T} {
|
function isMap<T>(value: SingleOrListOrMap<T>): value is {[key: string]: T} {
|
||||||
return value && !Array.isArray(value) && typeof value === 'object';
|
return value && !Array.isArray(value) && typeof value === 'object';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injector, Type} from '@angular/core';
|
import {Injector, Type} from '@angular/core';
|
||||||
import * as angular from './angular1';
|
|
||||||
|
import {IInjectorService, INgModelController} from './angular1';
|
||||||
import {DOWNGRADED_MODULE_COUNT_KEY, UPGRADE_APP_TYPE_KEY} from './constants';
|
import {DOWNGRADED_MODULE_COUNT_KEY, UPGRADE_APP_TYPE_KEY} from './constants';
|
||||||
|
|
||||||
const DIRECTIVE_PREFIX_REGEXP = /^(?:x|data)[:\-_]/i;
|
const DIRECTIVE_PREFIX_REGEXP = /^(?:x|data)[:\-_]/i;
|
||||||
|
@ -38,12 +39,12 @@ export function getTypeName(type: Type<any>): string {
|
||||||
return (type as any).overriddenName || type.name || type.toString().split('\n')[0];
|
return (type as any).overriddenName || type.name || type.toString().split('\n')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDowngradedModuleCount($injector: angular.IInjectorService): number {
|
export function getDowngradedModuleCount($injector: IInjectorService): number {
|
||||||
return $injector.has(DOWNGRADED_MODULE_COUNT_KEY) ? $injector.get(DOWNGRADED_MODULE_COUNT_KEY) :
|
return $injector.has(DOWNGRADED_MODULE_COUNT_KEY) ? $injector.get(DOWNGRADED_MODULE_COUNT_KEY) :
|
||||||
0;
|
0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUpgradeAppType($injector: angular.IInjectorService): UpgradeAppType {
|
export function getUpgradeAppType($injector: IInjectorService): UpgradeAppType {
|
||||||
return $injector.has(UPGRADE_APP_TYPE_KEY) ? $injector.get(UPGRADE_APP_TYPE_KEY) :
|
return $injector.has(UPGRADE_APP_TYPE_KEY) ? $injector.get(UPGRADE_APP_TYPE_KEY) :
|
||||||
UpgradeAppType.None;
|
UpgradeAppType.None;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ export function isFunction(value: any): value is Function {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateInjectionKey(
|
export function validateInjectionKey(
|
||||||
$injector: angular.IInjectorService, downgradedModule: string, injectionKey: string,
|
$injector: IInjectorService, downgradedModule: string, injectionKey: string,
|
||||||
attemptedAction: string): void {
|
attemptedAction: string): void {
|
||||||
const upgradeAppType = getUpgradeAppType($injector);
|
const upgradeAppType = getUpgradeAppType($injector);
|
||||||
const downgradedModuleCount = getDowngradedModuleCount($injector);
|
const downgradedModuleCount = getDowngradedModuleCount($injector);
|
||||||
|
@ -141,7 +142,7 @@ function supportsNgModel(component: any) {
|
||||||
* Glue the AngularJS `NgModelController` (if it exists) to the component
|
* Glue the AngularJS `NgModelController` (if it exists) to the component
|
||||||
* (if it implements the needed subset of the `ControlValueAccessor` interface).
|
* (if it implements the needed subset of the `ControlValueAccessor` interface).
|
||||||
*/
|
*/
|
||||||
export function hookupNgModel(ngModel: angular.INgModelController, component: any) {
|
export function hookupNgModel(ngModel: INgModelController, component: any) {
|
||||||
if (ngModel && supportsNgModel(component)) {
|
if (ngModel && supportsNgModel(component)) {
|
||||||
ngModel.$render = () => { component.writeValue(ngModel.$viewValue); };
|
ngModel.$render = () => { component.writeValue(ngModel.$viewValue); };
|
||||||
component.registerOnChange(ngModel.$setViewValue.bind(ngModel));
|
component.registerOnChange(ngModel.$setViewValue.bind(ngModel));
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {Compiler, CompilerOptions, Injector, NgModule, NgModuleRef, NgZone, StaticProvider, Testability, Type, resolveForwardRef} from '@angular/core';
|
import {Compiler, CompilerOptions, Injector, NgModule, NgModuleRef, NgZone, StaticProvider, Testability, Type, resolveForwardRef} from '@angular/core';
|
||||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
import * as angular from '../common/angular1';
|
import {IAngularBootstrapConfig, IAugmentedJQuery, IInjectorService, IModule, IProvideService, IRootScopeService, ITestabilityService, bootstrap, element as angularElement, module as angularModule} from '../common/angular1';
|
||||||
import {$$TESTABILITY, $COMPILE, $INJECTOR, $ROOT_SCOPE, COMPILER_KEY, INJECTOR_KEY, LAZY_MODULE_REF, NG_ZONE_KEY, UPGRADE_APP_TYPE_KEY} from '../common/constants';
|
import {$$TESTABILITY, $COMPILE, $INJECTOR, $ROOT_SCOPE, COMPILER_KEY, INJECTOR_KEY, LAZY_MODULE_REF, NG_ZONE_KEY, UPGRADE_APP_TYPE_KEY} from '../common/constants';
|
||||||
import {downgradeComponent} from '../common/downgrade_component';
|
import {downgradeComponent} from '../common/downgrade_component';
|
||||||
import {downgradeInjectable} from '../common/downgrade_injectable';
|
import {downgradeInjectable} from '../common/downgrade_injectable';
|
||||||
|
@ -117,10 +117,10 @@ export class UpgradeAdapter {
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
private ngZone !: NgZone;
|
private ngZone !: NgZone;
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
private ng1Module !: angular.IModule;
|
private ng1Module !: IModule;
|
||||||
private moduleRef: NgModuleRef<any>|null = null;
|
private moduleRef: NgModuleRef<any>|null = null;
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
private ng2BootstrapDeferred !: Deferred<angular.IInjectorService>;
|
private ng2BootstrapDeferred !: Deferred<IInjectorService>;
|
||||||
|
|
||||||
constructor(private ng2AppModule: Type<any>, private compilerOptions?: CompilerOptions) {
|
constructor(private ng2AppModule: Type<any>, private compilerOptions?: CompilerOptions) {
|
||||||
if (!ng2AppModule) {
|
if (!ng2AppModule) {
|
||||||
|
@ -382,7 +382,7 @@ export class UpgradeAdapter {
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig):
|
bootstrap(element: Element, modules?: any[], config?: IAngularBootstrapConfig):
|
||||||
UpgradeAdapterRef {
|
UpgradeAdapterRef {
|
||||||
this.declareNg1Module(modules);
|
this.declareNg1Module(modules);
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ export class UpgradeAdapter {
|
||||||
const windowAngular = (window as any /** TODO #???? */)['angular'];
|
const windowAngular = (window as any /** TODO #???? */)['angular'];
|
||||||
windowAngular.resumeBootstrap = undefined;
|
windowAngular.resumeBootstrap = undefined;
|
||||||
|
|
||||||
this.ngZone.run(() => { angular.bootstrap(element, [this.ng1Module.name], config !); });
|
this.ngZone.run(() => { bootstrap(element, [this.ng1Module.name], config !); });
|
||||||
const ng1BootstrapPromise = new Promise((resolve) => {
|
const ng1BootstrapPromise = new Promise((resolve) => {
|
||||||
if (windowAngular.resumeBootstrap) {
|
if (windowAngular.resumeBootstrap) {
|
||||||
const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
|
const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
|
||||||
|
@ -408,7 +408,7 @@ export class UpgradeAdapter {
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all([this.ng2BootstrapDeferred.promise, ng1BootstrapPromise]).then(([ng1Injector]) => {
|
Promise.all([this.ng2BootstrapDeferred.promise, ng1BootstrapPromise]).then(([ng1Injector]) => {
|
||||||
angular.element(element).data !(controllerKey(INJECTOR_KEY), this.moduleRef !.injector);
|
angularElement(element).data !(controllerKey(INJECTOR_KEY), this.moduleRef !.injector);
|
||||||
this.moduleRef !.injector.get<NgZone>(NgZone).run(
|
this.moduleRef !.injector.get<NgZone>(NgZone).run(
|
||||||
() => { (<any>upgrade)._bootstrapDone(this.moduleRef, ng1Injector); });
|
() => { (<any>upgrade)._bootstrapDone(this.moduleRef, ng1Injector); });
|
||||||
}, onError);
|
}, onError);
|
||||||
|
@ -450,7 +450,7 @@ export class UpgradeAdapter {
|
||||||
const token = options && options.asToken || name;
|
const token = options && options.asToken || name;
|
||||||
this.upgradedProviders.push({
|
this.upgradedProviders.push({
|
||||||
provide: token,
|
provide: token,
|
||||||
useFactory: ($injector: angular.IInjectorService) => $injector.get(name),
|
useFactory: ($injector: IInjectorService) => $injector.get(name),
|
||||||
deps: [$INJECTOR]
|
deps: [$INJECTOR]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -495,13 +495,13 @@ export class UpgradeAdapter {
|
||||||
* upgradeAdapter.declareNg1Module(['heroApp']);
|
* upgradeAdapter.declareNg1Module(['heroApp']);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
private declareNg1Module(modules: string[] = []): angular.IModule {
|
private declareNg1Module(modules: string[] = []): IModule {
|
||||||
const delayApplyExps: Function[] = [];
|
const delayApplyExps: Function[] = [];
|
||||||
let original$applyFn: Function;
|
let original$applyFn: Function;
|
||||||
let rootScopePrototype: any;
|
let rootScopePrototype: any;
|
||||||
let rootScope: angular.IRootScopeService;
|
let rootScope: IRootScopeService;
|
||||||
const upgradeAdapter = this;
|
const upgradeAdapter = this;
|
||||||
const ng1Module = this.ng1Module = angular.module(this.idPrefix, modules);
|
const ng1Module = this.ng1Module = angularModule(this.idPrefix, modules);
|
||||||
const platformRef = platformBrowserDynamic();
|
const platformRef = platformBrowserDynamic();
|
||||||
|
|
||||||
this.ngZone = new NgZone({enableLongStackTrace: Zone.hasOwnProperty('longStackTraceZoneSpec')});
|
this.ngZone = new NgZone({enableLongStackTrace: Zone.hasOwnProperty('longStackTraceZoneSpec')});
|
||||||
|
@ -515,10 +515,10 @@ export class UpgradeAdapter {
|
||||||
.factory(COMPILER_KEY, () => this.moduleRef !.injector.get(Compiler))
|
.factory(COMPILER_KEY, () => this.moduleRef !.injector.get(Compiler))
|
||||||
.config([
|
.config([
|
||||||
'$provide', '$injector',
|
'$provide', '$injector',
|
||||||
(provide: angular.IProvideService, ng1Injector: angular.IInjectorService) => {
|
(provide: IProvideService, ng1Injector: IInjectorService) => {
|
||||||
provide.decorator($ROOT_SCOPE, [
|
provide.decorator($ROOT_SCOPE, [
|
||||||
'$delegate',
|
'$delegate',
|
||||||
function(rootScopeDelegate: angular.IRootScopeService) {
|
function(rootScopeDelegate: IRootScopeService) {
|
||||||
// Capture the root apply so that we can delay first call to $apply until we
|
// Capture the root apply so that we can delay first call to $apply until we
|
||||||
// bootstrap Angular and then we replay and restore the $apply.
|
// bootstrap Angular and then we replay and restore the $apply.
|
||||||
rootScopePrototype = rootScopeDelegate.constructor.prototype;
|
rootScopePrototype = rootScopeDelegate.constructor.prototype;
|
||||||
|
@ -534,7 +534,7 @@ export class UpgradeAdapter {
|
||||||
if (ng1Injector.has($$TESTABILITY)) {
|
if (ng1Injector.has($$TESTABILITY)) {
|
||||||
provide.decorator($$TESTABILITY, [
|
provide.decorator($$TESTABILITY, [
|
||||||
'$delegate',
|
'$delegate',
|
||||||
function(testabilityDelegate: angular.ITestabilityService) {
|
function(testabilityDelegate: ITestabilityService) {
|
||||||
const originalWhenStable: Function = testabilityDelegate.whenStable;
|
const originalWhenStable: Function = testabilityDelegate.whenStable;
|
||||||
// Cannot use arrow function below because we need the context
|
// Cannot use arrow function below because we need the context
|
||||||
const newWhenStable = function(callback: Function) {
|
const newWhenStable = function(callback: Function) {
|
||||||
|
@ -559,7 +559,7 @@ export class UpgradeAdapter {
|
||||||
|
|
||||||
ng1Module.run([
|
ng1Module.run([
|
||||||
'$injector', '$rootScope',
|
'$injector', '$rootScope',
|
||||||
(ng1Injector: angular.IInjectorService, rootScope: angular.IRootScopeService) => {
|
(ng1Injector: IInjectorService, rootScope: IRootScopeService) => {
|
||||||
UpgradeNg1ComponentAdapterBuilder.resolve(this.ng1ComponentsToBeUpgraded, ng1Injector)
|
UpgradeNg1ComponentAdapterBuilder.resolve(this.ng1ComponentsToBeUpgraded, ng1Injector)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Note: There is a bug in TS 2.4 that prevents us from
|
// Note: There is a bug in TS 2.4 that prevents us from
|
||||||
|
@ -620,7 +620,7 @@ class ParentInjectorPromise {
|
||||||
private injector !: Injector;
|
private injector !: Injector;
|
||||||
private callbacks: ((injector: Injector) => any)[] = [];
|
private callbacks: ((injector: Injector) => any)[] = [];
|
||||||
|
|
||||||
constructor(private element: angular.IAugmentedJQuery) {
|
constructor(private element: IAugmentedJQuery) {
|
||||||
// store the promise on the element
|
// store the promise on the element
|
||||||
element.data !(controllerKey(INJECTOR_KEY), this);
|
element.data !(controllerKey(INJECTOR_KEY), this);
|
||||||
}
|
}
|
||||||
|
@ -660,13 +660,13 @@ export class UpgradeAdapterRef {
|
||||||
/* @internal */
|
/* @internal */
|
||||||
private _readyFn: ((upgradeAdapterRef?: UpgradeAdapterRef) => void)|null = null;
|
private _readyFn: ((upgradeAdapterRef?: UpgradeAdapterRef) => void)|null = null;
|
||||||
|
|
||||||
public ng1RootScope: angular.IRootScopeService = null !;
|
public ng1RootScope: IRootScopeService = null !;
|
||||||
public ng1Injector: angular.IInjectorService = null !;
|
public ng1Injector: IInjectorService = null !;
|
||||||
public ng2ModuleRef: NgModuleRef<any> = null !;
|
public ng2ModuleRef: NgModuleRef<any> = null !;
|
||||||
public ng2Injector: Injector = null !;
|
public ng2Injector: Injector = null !;
|
||||||
|
|
||||||
/* @internal */
|
/* @internal */
|
||||||
private _bootstrapDone(ngModuleRef: NgModuleRef<any>, ng1Injector: angular.IInjectorService) {
|
private _bootstrapDone(ngModuleRef: NgModuleRef<any>, ng1Injector: IInjectorService) {
|
||||||
this.ng2ModuleRef = ngModuleRef;
|
this.ng2ModuleRef = ngModuleRef;
|
||||||
this.ng2Injector = ngModuleRef.injector;
|
this.ng2Injector = ngModuleRef.injector;
|
||||||
this.ng1Injector = ng1Injector;
|
this.ng1Injector = ng1Injector;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {Directive, DoCheck, ElementRef, EventEmitter, Inject, Injector, OnChanges, OnDestroy, OnInit, SimpleChange, SimpleChanges, Type} from '@angular/core';
|
import {Directive, DoCheck, ElementRef, EventEmitter, Inject, Injector, OnChanges, OnDestroy, OnInit, SimpleChange, SimpleChanges, Type} from '@angular/core';
|
||||||
|
|
||||||
import * as angular from '../common/angular1';
|
import {IAttributes, IDirective, IDirectivePrePost, IInjectorService, ILinkFn, IScope, ITranscludeFunction} from '../common/angular1';
|
||||||
import {$SCOPE} from '../common/constants';
|
import {$SCOPE} from '../common/constants';
|
||||||
import {IBindingDestination, IControllerInstance, UpgradeHelper} from '../common/upgrade_helper';
|
import {IBindingDestination, IControllerInstance, UpgradeHelper} from '../common/upgrade_helper';
|
||||||
import {isFunction, strictEquals} from '../common/util';
|
import {isFunction, strictEquals} from '../common/util';
|
||||||
|
@ -31,7 +31,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||||
propertyOutputs: string[] = [];
|
propertyOutputs: string[] = [];
|
||||||
checkProperties: string[] = [];
|
checkProperties: string[] = [];
|
||||||
propertyMap: {[name: string]: string} = {};
|
propertyMap: {[name: string]: string} = {};
|
||||||
directive: angular.IDirective|null = null;
|
directive: IDirective|null = null;
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
template !: string;
|
template !: string;
|
||||||
|
|
||||||
|
@ -48,8 +48,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||||
@Directive({jit: true, ...directive})
|
@Directive({jit: true, ...directive})
|
||||||
class MyClass extends UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck,
|
class MyClass extends UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck,
|
||||||
OnDestroy {
|
OnDestroy {
|
||||||
constructor(
|
constructor(@Inject($SCOPE) scope: IScope, injector: Injector, elementRef: ElementRef) {
|
||||||
@Inject($SCOPE) scope: angular.IScope, injector: Injector, elementRef: ElementRef) {
|
|
||||||
super(
|
super(
|
||||||
new UpgradeHelper(injector, name, elementRef, self.directive || undefined), scope,
|
new UpgradeHelper(injector, name, elementRef, self.directive || undefined), scope,
|
||||||
self.template, self.inputs, self.outputs, self.propertyOutputs, self.checkProperties,
|
self.template, self.inputs, self.outputs, self.propertyOutputs, self.checkProperties,
|
||||||
|
@ -121,7 +120,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||||
*/
|
*/
|
||||||
static resolve(
|
static resolve(
|
||||||
exportedComponents: {[name: string]: UpgradeNg1ComponentAdapterBuilder},
|
exportedComponents: {[name: string]: UpgradeNg1ComponentAdapterBuilder},
|
||||||
$injector: angular.IInjectorService): Promise<string[]> {
|
$injector: IInjectorService): Promise<string[]> {
|
||||||
const promises = Object.keys(exportedComponents).map(name => {
|
const promises = Object.keys(exportedComponents).map(name => {
|
||||||
const exportedComponent = exportedComponents[name];
|
const exportedComponent = exportedComponents[name];
|
||||||
exportedComponent.directive = UpgradeHelper.getDirective($injector, name);
|
exportedComponent.directive = UpgradeHelper.getDirective($injector, name);
|
||||||
|
@ -140,13 +139,13 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||||
private controllerInstance: IControllerInstance|null = null;
|
private controllerInstance: IControllerInstance|null = null;
|
||||||
destinationObj: IBindingDestination|null = null;
|
destinationObj: IBindingDestination|null = null;
|
||||||
checkLastValues: any[] = [];
|
checkLastValues: any[] = [];
|
||||||
directive: angular.IDirective;
|
directive: IDirective;
|
||||||
element: Element;
|
element: Element;
|
||||||
$element: any = null;
|
$element: any = null;
|
||||||
componentScope: angular.IScope;
|
componentScope: IScope;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private helper: UpgradeHelper, scope: angular.IScope, private template: string,
|
private helper: UpgradeHelper, scope: IScope, private template: string,
|
||||||
private inputs: string[], private outputs: string[], private propOuts: string[],
|
private inputs: string[], private outputs: string[], private propOuts: string[],
|
||||||
private checkProperties: string[], private propertyMap: {[key: string]: string}) {
|
private checkProperties: string[], private propertyMap: {[key: string]: string}) {
|
||||||
this.directive = helper.directive;
|
this.directive = helper.directive;
|
||||||
|
@ -180,7 +179,7 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// Collect contents, insert and compile template
|
// Collect contents, insert and compile template
|
||||||
const attachChildNodes: angular.ILinkFn|undefined = this.helper.prepareTransclusion();
|
const attachChildNodes: ILinkFn|undefined = this.helper.prepareTransclusion();
|
||||||
const linkFn = this.helper.compileTemplate(this.template);
|
const linkFn = this.helper.compileTemplate(this.template);
|
||||||
|
|
||||||
// Instantiate controller (if not already done so)
|
// Instantiate controller (if not already done so)
|
||||||
|
@ -201,10 +200,10 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||||
|
|
||||||
// Linking
|
// Linking
|
||||||
const link = this.directive.link;
|
const link = this.directive.link;
|
||||||
const preLink = (typeof link == 'object') && (link as angular.IDirectivePrePost).pre;
|
const preLink = (typeof link == 'object') && (link as IDirectivePrePost).pre;
|
||||||
const postLink = (typeof link == 'object') ? (link as angular.IDirectivePrePost).post : link;
|
const postLink = (typeof link == 'object') ? (link as IDirectivePrePost).post : link;
|
||||||
const attrs: angular.IAttributes = NOT_SUPPORTED;
|
const attrs: IAttributes = NOT_SUPPORTED;
|
||||||
const transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
|
const transcludeFn: ITranscludeFunction = NOT_SUPPORTED;
|
||||||
if (preLink) {
|
if (preLink) {
|
||||||
preLink(this.componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
preLink(this.componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @license
|
* @license
|
||||||
* Copyright Google Inc. All Rights Reserved.
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
@ -6,14 +7,14 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as angular from '../common/angular1';
|
import {IInjectorService} from '../common/angular1';
|
||||||
|
|
||||||
// We have to do a little dance to get the ng1 injector into the module injector.
|
// We have to do a little dance to get the ng1 injector into the module injector.
|
||||||
// We store the ng1 injector so that the provider in the module injector can access it
|
// We store the ng1 injector so that the provider in the module injector can access it
|
||||||
// Then we "get" the ng1 injector from the module injector, which triggers the provider to read
|
// Then we "get" the ng1 injector from the module injector, which triggers the provider to read
|
||||||
// the stored injector and release the reference to it.
|
// the stored injector and release the reference to it.
|
||||||
let tempInjectorRef: angular.IInjectorService|null = null;
|
let tempInjectorRef: IInjectorService|null = null;
|
||||||
export function setTempInjectorRef(injector: angular.IInjectorService) {
|
export function setTempInjectorRef(injector: IInjectorService) {
|
||||||
tempInjectorRef = injector;
|
tempInjectorRef = injector;
|
||||||
}
|
}
|
||||||
export function injectorFactory() {
|
export function injectorFactory() {
|
||||||
|
@ -21,20 +22,20 @@ export function injectorFactory() {
|
||||||
throw new Error('Trying to get the AngularJS injector before it being set.');
|
throw new Error('Trying to get the AngularJS injector before it being set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const injector: angular.IInjectorService = tempInjectorRef;
|
const injector: IInjectorService = tempInjectorRef;
|
||||||
tempInjectorRef = null; // clear the value to prevent memory leaks
|
tempInjectorRef = null; // clear the value to prevent memory leaks
|
||||||
return injector;
|
return injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function rootScopeFactory(i: angular.IInjectorService) {
|
export function rootScopeFactory(i: IInjectorService) {
|
||||||
return i.get('$rootScope');
|
return i.get('$rootScope');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function compileFactory(i: angular.IInjectorService) {
|
export function compileFactory(i: IInjectorService) {
|
||||||
return i.get('$compile');
|
return i.get('$compile');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseFactory(i: angular.IInjectorService) {
|
export function parseFactory(i: IInjectorService) {
|
||||||
return i.get('$parse');
|
return i.get('$parse');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {Injector, NgModuleFactory, NgModuleRef, StaticProvider} from '@angular/core';
|
import {Injector, NgModuleFactory, NgModuleRef, StaticProvider} from '@angular/core';
|
||||||
import {platformBrowser} from '@angular/platform-browser';
|
import {platformBrowser} from '@angular/platform-browser';
|
||||||
|
|
||||||
import * as angular from '../common/angular1';
|
import {IInjectorService, IProvideService, module as angularModule} from '../common/angular1';
|
||||||
import {$INJECTOR, $PROVIDE, DOWNGRADED_MODULE_COUNT_KEY, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../common/constants';
|
import {$INJECTOR, $PROVIDE, DOWNGRADED_MODULE_COUNT_KEY, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../common/constants';
|
||||||
import {LazyModuleRef, UpgradeAppType, getDowngradedModuleCount, isFunction} from '../common/util';
|
import {LazyModuleRef, UpgradeAppType, getDowngradedModuleCount, isFunction} from '../common/util';
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ export function downgradeModule<T>(
|
||||||
let injector: Injector;
|
let injector: Injector;
|
||||||
|
|
||||||
// Create an ng1 module to bootstrap.
|
// Create an ng1 module to bootstrap.
|
||||||
angular.module(lazyModuleName, [])
|
angularModule(lazyModuleName, [])
|
||||||
.constant(UPGRADE_APP_TYPE_KEY, UpgradeAppType.Lite)
|
.constant(UPGRADE_APP_TYPE_KEY, UpgradeAppType.Lite)
|
||||||
.factory(INJECTOR_KEY, [lazyInjectorKey, identity])
|
.factory(INJECTOR_KEY, [lazyInjectorKey, identity])
|
||||||
.factory(
|
.factory(
|
||||||
|
@ -161,7 +161,7 @@ export function downgradeModule<T>(
|
||||||
lazyModuleRefKey,
|
lazyModuleRefKey,
|
||||||
[
|
[
|
||||||
$INJECTOR,
|
$INJECTOR,
|
||||||
($injector: angular.IInjectorService) => {
|
($injector: IInjectorService) => {
|
||||||
setTempInjectorRef($injector);
|
setTempInjectorRef($injector);
|
||||||
const result: LazyModuleRef = {
|
const result: LazyModuleRef = {
|
||||||
promise: bootstrapFn(angular1Providers).then(ref => {
|
promise: bootstrapFn(angular1Providers).then(ref => {
|
||||||
|
@ -176,7 +176,7 @@ export function downgradeModule<T>(
|
||||||
])
|
])
|
||||||
.config([
|
.config([
|
||||||
$INJECTOR, $PROVIDE,
|
$INJECTOR, $PROVIDE,
|
||||||
($injector: angular.IInjectorService, $provide: angular.IProvideService) => {
|
($injector: IInjectorService, $provide: IProvideService) => {
|
||||||
$provide.constant(DOWNGRADED_MODULE_COUNT_KEY, getDowngradedModuleCount($injector) + 1);
|
$provide.constant(DOWNGRADED_MODULE_COUNT_KEY, getDowngradedModuleCount($injector) + 1);
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DoCheck, ElementRef, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, SimpleChanges, ɵlooseIdentical as looseIdentical} from '@angular/core';
|
import {DoCheck, ElementRef, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, SimpleChanges, ɵlooseIdentical as looseIdentical} from '@angular/core';
|
||||||
import * as angular from '../common/angular1';
|
|
||||||
|
import {IAttributes, IAugmentedJQuery, IDirective, IDirectivePrePost, IInjectorService, ILinkFn, IScope, ITranscludeFunction} from '../common/angular1';
|
||||||
import {$SCOPE} from '../common/constants';
|
import {$SCOPE} from '../common/constants';
|
||||||
import {IBindingDestination, IControllerInstance, UpgradeHelper} from '../common/upgrade_helper';
|
import {IBindingDestination, IControllerInstance, UpgradeHelper} from '../common/upgrade_helper';
|
||||||
import {isFunction} from '../common/util';
|
import {isFunction} from '../common/util';
|
||||||
|
@ -68,13 +69,13 @@ class Bindings {
|
||||||
export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||||
private helper: UpgradeHelper;
|
private helper: UpgradeHelper;
|
||||||
|
|
||||||
private $injector: angular.IInjectorService;
|
private $injector: IInjectorService;
|
||||||
|
|
||||||
private element: Element;
|
private element: Element;
|
||||||
private $element: angular.IAugmentedJQuery;
|
private $element: IAugmentedJQuery;
|
||||||
private $componentScope: angular.IScope;
|
private $componentScope: IScope;
|
||||||
|
|
||||||
private directive: angular.IDirective;
|
private directive: IDirective;
|
||||||
private bindings: Bindings;
|
private bindings: Bindings;
|
||||||
|
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
|
@ -125,7 +126,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// Collect contents, insert and compile template
|
// Collect contents, insert and compile template
|
||||||
const attachChildNodes: angular.ILinkFn|undefined = this.helper.prepareTransclusion();
|
const attachChildNodes: ILinkFn|undefined = this.helper.prepareTransclusion();
|
||||||
const linkFn = this.helper.compileTemplate();
|
const linkFn = this.helper.compileTemplate();
|
||||||
|
|
||||||
// Instantiate controller
|
// Instantiate controller
|
||||||
|
@ -167,10 +168,10 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||||
|
|
||||||
// Linking
|
// Linking
|
||||||
const link = this.directive.link;
|
const link = this.directive.link;
|
||||||
const preLink = (typeof link == 'object') && (link as angular.IDirectivePrePost).pre;
|
const preLink = (typeof link == 'object') && (link as IDirectivePrePost).pre;
|
||||||
const postLink = (typeof link == 'object') ? (link as angular.IDirectivePrePost).post : link;
|
const postLink = (typeof link == 'object') ? (link as IDirectivePrePost).post : link;
|
||||||
const attrs: angular.IAttributes = NOT_SUPPORTED;
|
const attrs: IAttributes = NOT_SUPPORTED;
|
||||||
const transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
|
const transcludeFn: ITranscludeFunction = NOT_SUPPORTED;
|
||||||
if (preLink) {
|
if (preLink) {
|
||||||
preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
||||||
}
|
}
|
||||||
|
@ -221,7 +222,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||||
this.helper.onDestroy(this.$componentScope, this.controllerInstance);
|
this.helper.onDestroy(this.$componentScope, this.controllerInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private initializeBindings(directive: angular.IDirective) {
|
private initializeBindings(directive: IDirective) {
|
||||||
const btcIsObject = typeof directive.bindToController === 'object';
|
const btcIsObject = typeof directive.bindToController === 'object';
|
||||||
if (btcIsObject && Object.keys(directive.scope !).length) {
|
if (btcIsObject && Object.keys(directive.scope !).length) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {Injector, NgModule, NgZone, Testability} from '@angular/core';
|
import {Injector, NgModule, NgZone, Testability} from '@angular/core';
|
||||||
|
|
||||||
import * as angular from '../common/angular1';
|
import {IInjectorService, IIntervalService, IProvideService, ITestabilityService, bootstrap, element as angularElement, module as angularModule} from '../common/angular1';
|
||||||
import {$$TESTABILITY, $DELEGATE, $INJECTOR, $INTERVAL, $PROVIDE, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../common/constants';
|
import {$$TESTABILITY, $DELEGATE, $INJECTOR, $INTERVAL, $PROVIDE, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../common/constants';
|
||||||
import {LazyModuleRef, UpgradeAppType, controllerKey} from '../common/util';
|
import {LazyModuleRef, UpgradeAppType, controllerKey} from '../common/util';
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import {angular1Providers, setTempInjectorRef} from './angular1_providers';
|
||||||
import {NgAdapterInjector} from './util';
|
import {NgAdapterInjector} from './util';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description
|
||||||
*
|
*
|
||||||
|
@ -170,8 +171,7 @@ export class UpgradeModule {
|
||||||
|
|
||||||
// Create an ng1 module to bootstrap
|
// Create an ng1 module to bootstrap
|
||||||
const initModule =
|
const initModule =
|
||||||
angular
|
angularModule(INIT_MODULE_NAME, [])
|
||||||
.module(INIT_MODULE_NAME, [])
|
|
||||||
|
|
||||||
.constant(UPGRADE_APP_TYPE_KEY, UpgradeAppType.Static)
|
.constant(UPGRADE_APP_TYPE_KEY, UpgradeAppType.Static)
|
||||||
|
|
||||||
|
@ -183,11 +183,11 @@ export class UpgradeModule {
|
||||||
|
|
||||||
.config([
|
.config([
|
||||||
$PROVIDE, $INJECTOR,
|
$PROVIDE, $INJECTOR,
|
||||||
($provide: angular.IProvideService, $injector: angular.IInjectorService) => {
|
($provide: IProvideService, $injector: IInjectorService) => {
|
||||||
if ($injector.has($$TESTABILITY)) {
|
if ($injector.has($$TESTABILITY)) {
|
||||||
$provide.decorator($$TESTABILITY, [
|
$provide.decorator($$TESTABILITY, [
|
||||||
$DELEGATE,
|
$DELEGATE,
|
||||||
(testabilityDelegate: angular.ITestabilityService) => {
|
(testabilityDelegate: ITestabilityService) => {
|
||||||
const originalWhenStable: Function = testabilityDelegate.whenStable;
|
const originalWhenStable: Function = testabilityDelegate.whenStable;
|
||||||
const injector = this.injector;
|
const injector = this.injector;
|
||||||
// Cannot use arrow function below because we need the context
|
// Cannot use arrow function below because we need the context
|
||||||
|
@ -212,7 +212,7 @@ export class UpgradeModule {
|
||||||
if ($injector.has($INTERVAL)) {
|
if ($injector.has($INTERVAL)) {
|
||||||
$provide.decorator($INTERVAL, [
|
$provide.decorator($INTERVAL, [
|
||||||
$DELEGATE,
|
$DELEGATE,
|
||||||
(intervalDelegate: angular.IIntervalService) => {
|
(intervalDelegate: IIntervalService) => {
|
||||||
// Wrap the $interval service so that setInterval is called outside NgZone,
|
// Wrap the $interval service so that setInterval is called outside NgZone,
|
||||||
// but the callback is still invoked within it. This is so that $interval
|
// but the callback is still invoked within it. This is so that $interval
|
||||||
// won't block stability, which preserves the behavior from AngularJS.
|
// won't block stability, which preserves the behavior from AngularJS.
|
||||||
|
@ -240,7 +240,7 @@ export class UpgradeModule {
|
||||||
|
|
||||||
.run([
|
.run([
|
||||||
$INJECTOR,
|
$INJECTOR,
|
||||||
($injector: angular.IInjectorService) => {
|
($injector: IInjectorService) => {
|
||||||
this.$injector = $injector;
|
this.$injector = $injector;
|
||||||
|
|
||||||
// Initialize the ng1 $injector provider
|
// Initialize the ng1 $injector provider
|
||||||
|
@ -248,7 +248,7 @@ export class UpgradeModule {
|
||||||
this.injector.get($INJECTOR);
|
this.injector.get($INJECTOR);
|
||||||
|
|
||||||
// Put the injector on the DOM, so that it can be "required"
|
// Put the injector on the DOM, so that it can be "required"
|
||||||
angular.element(element).data !(controllerKey(INJECTOR_KEY), this.injector);
|
angularElement(element).data !(controllerKey(INJECTOR_KEY), this.injector);
|
||||||
|
|
||||||
// Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
|
// Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
|
||||||
// We need to do this in the next tick so that we don't prevent the bootup
|
// We need to do this in the next tick so that we don't prevent the bootup
|
||||||
|
@ -262,14 +262,14 @@ export class UpgradeModule {
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
|
const upgradeModule = angularModule(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
|
||||||
|
|
||||||
// Make sure resumeBootstrap() only exists if the current bootstrap is deferred
|
// Make sure resumeBootstrap() only exists if the current bootstrap is deferred
|
||||||
const windowAngular = (window as any)['angular'];
|
const windowAngular = (window as any)['angular'];
|
||||||
windowAngular.resumeBootstrap = undefined;
|
windowAngular.resumeBootstrap = undefined;
|
||||||
|
|
||||||
// Bootstrap the AngularJS application inside our zone
|
// Bootstrap the AngularJS application inside our zone
|
||||||
this.ngZone.run(() => { angular.bootstrap(element, [upgradeModule.name], config); });
|
this.ngZone.run(() => { bootstrap(element, [upgradeModule.name], config); });
|
||||||
|
|
||||||
// Patch resumeBootstrap() to run inside the ngZone
|
// Patch resumeBootstrap() to run inside the ngZone
|
||||||
if (windowAngular.resumeBootstrap) {
|
if (windowAngular.resumeBootstrap) {
|
||||||
|
|
Loading…
Reference in New Issue