fix(upgrade): Update types for TypeScript nullability support
Closes #15897
This commit is contained in:

committed by
Tobias Bosch

parent
a0d124bd91
commit
01d93f3af8
@ -84,7 +84,7 @@ export function downgradeComponent(info: {
|
||||
const componentFactoryResolver: ComponentFactoryResolver =
|
||||
injector.get(ComponentFactoryResolver);
|
||||
const componentFactory: ComponentFactory<any> =
|
||||
componentFactoryResolver.resolveComponentFactory(info.component);
|
||||
componentFactoryResolver.resolveComponentFactory(info.component) !;
|
||||
|
||||
if (!componentFactory) {
|
||||
throw new Error('Expecting ComponentFactory for: ' + getComponentName(info.component));
|
||||
@ -130,7 +130,7 @@ class ParentInjectorPromise {
|
||||
|
||||
constructor(private element: angular.IAugmentedJQuery) {
|
||||
// Store the promise on the element.
|
||||
element.data(this.injectorKey, this);
|
||||
element.data !(this.injectorKey, this);
|
||||
}
|
||||
|
||||
then(callback: (injector: Injector) => any) {
|
||||
@ -145,10 +145,10 @@ class ParentInjectorPromise {
|
||||
this.injector = injector;
|
||||
|
||||
// Store the real injector on the element.
|
||||
this.element.data(this.injectorKey, injector);
|
||||
this.element.data !(this.injectorKey, injector);
|
||||
|
||||
// Release the element to prevent memory leaks.
|
||||
this.element = null;
|
||||
this.element = null !;
|
||||
|
||||
// Run the queued callbacks.
|
||||
this.callbacks.forEach(callback => callback(injector));
|
||||
|
@ -19,11 +19,11 @@ const INITIAL_VALUE = {
|
||||
|
||||
export class DowngradeComponentAdapter {
|
||||
private inputChangeCount: number = 0;
|
||||
private inputChanges: SimpleChanges = null;
|
||||
private inputChanges: SimpleChanges|null = null;
|
||||
private componentScope: angular.IScope;
|
||||
private componentRef: ComponentRef<any> = null;
|
||||
private componentRef: ComponentRef<any>|null = null;
|
||||
private component: any = null;
|
||||
private changeDetector: ChangeDetectorRef = null;
|
||||
private changeDetector: ChangeDetectorRef|null = null;
|
||||
|
||||
constructor(
|
||||
private id: string, private element: angular.IAugmentedJQuery,
|
||||
@ -40,12 +40,12 @@ export class DowngradeComponentAdapter {
|
||||
const projectableNodes: Node[][] = this.groupProjectableNodes();
|
||||
const linkFns = projectableNodes.map(nodes => this.$compile(nodes));
|
||||
|
||||
this.element.empty();
|
||||
this.element.empty !();
|
||||
|
||||
linkFns.forEach(linkFn => {
|
||||
linkFn(this.scope, (clone: Node[]) => {
|
||||
compiledProjectableNodes.push(clone);
|
||||
this.element.append(clone);
|
||||
this.element.append !(clone);
|
||||
});
|
||||
});
|
||||
|
||||
@ -109,7 +109,7 @@ export class DowngradeComponentAdapter {
|
||||
this.componentScope.$watch(() => this.inputChangeCount, () => {
|
||||
const inputChanges = this.inputChanges;
|
||||
this.inputChanges = {};
|
||||
(<OnChanges>this.component).ngOnChanges(inputChanges);
|
||||
(<OnChanges>this.component).ngOnChanges(inputChanges !);
|
||||
});
|
||||
}
|
||||
this.componentScope.$watch(() => this.changeDetector && this.changeDetector.detectChanges());
|
||||
@ -133,11 +133,11 @@ export class DowngradeComponentAdapter {
|
||||
expr = (attrs as any /** TODO #9100 */)[output.onAttr];
|
||||
} else if (attrs.hasOwnProperty(output.parenAttr)) {
|
||||
expr = (attrs as any /** TODO #9100 */)[output.parenAttr];
|
||||
} else if (attrs.hasOwnProperty(bindonAttr)) {
|
||||
expr = (attrs as any /** TODO #9100 */)[bindonAttr];
|
||||
} else if (attrs.hasOwnProperty(bindonAttr !)) {
|
||||
expr = (attrs as any /** TODO #9100 */)[bindonAttr !];
|
||||
assignExpr = true;
|
||||
} else if (attrs.hasOwnProperty(bracketParenAttr)) {
|
||||
expr = (attrs as any /** TODO #9100 */)[bracketParenAttr];
|
||||
} else if (attrs.hasOwnProperty(bracketParenAttr !)) {
|
||||
expr = (attrs as any /** TODO #9100 */)[bracketParenAttr !];
|
||||
assignExpr = true;
|
||||
}
|
||||
|
||||
@ -164,13 +164,13 @@ export class DowngradeComponentAdapter {
|
||||
}
|
||||
|
||||
registerCleanup() {
|
||||
this.element.bind('$destroy', () => {
|
||||
this.element.bind !('$destroy', () => {
|
||||
this.componentScope.$destroy();
|
||||
this.componentRef.destroy();
|
||||
this.componentRef !.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
getInjector(): Injector { return this.componentRef && this.componentRef.injector; }
|
||||
getInjector(): Injector { return this.componentRef ! && this.componentRef !.injector; }
|
||||
|
||||
private updateInput(prop: string, prevValue: any, currValue: any) {
|
||||
if (this.inputChanges) {
|
||||
@ -183,7 +183,7 @@ export class DowngradeComponentAdapter {
|
||||
|
||||
groupProjectableNodes() {
|
||||
let ngContentSelectors = this.componentFactory.ngContentSelectors;
|
||||
return groupNodesBySelector(ngContentSelectors, this.element.contents());
|
||||
return groupNodesBySelector(ngContentSelectors, this.element.contents !());
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,9 +209,9 @@ export function groupNodesBySelector(ngContentSelectors: string[], nodes: Node[]
|
||||
return projectableNodes;
|
||||
}
|
||||
|
||||
function findMatchingNgContentIndex(element: any, ngContentSelectors: string[]): number {
|
||||
function findMatchingNgContentIndex(element: any, ngContentSelectors: string[]): number|null {
|
||||
const ngContentIndices: number[] = [];
|
||||
let wildcardNgContentIndex: number;
|
||||
let wildcardNgContentIndex: number = -1;
|
||||
for (let i = 0; i < ngContentSelectors.length; i++) {
|
||||
const selector = ngContentSelectors[i];
|
||||
if (selector === '*') {
|
||||
@ -224,7 +224,7 @@ function findMatchingNgContentIndex(element: any, ngContentSelectors: string[]):
|
||||
}
|
||||
ngContentIndices.sort();
|
||||
|
||||
if (wildcardNgContentIndex !== undefined) {
|
||||
if (wildcardNgContentIndex !== -1) {
|
||||
ngContentIndices.push(wildcardNgContentIndex);
|
||||
}
|
||||
return ngContentIndices.length ? ngContentIndices[0] : null;
|
||||
|
@ -26,12 +26,12 @@ export function controllerKey(name: string): string {
|
||||
|
||||
export function getAttributesAsArray(node: Node): [string, string][] {
|
||||
const attributes = node.attributes;
|
||||
let asArray: [string, string][];
|
||||
let asArray: [string, string][] = undefined !;
|
||||
if (attributes) {
|
||||
let attrLen = attributes.length;
|
||||
asArray = new Array(attrLen);
|
||||
for (let i = 0; i < attrLen; i++) {
|
||||
asArray[i] = [attributes[i].nodeName, attributes[i].nodeValue];
|
||||
asArray[i] = [attributes[i].nodeName, attributes[i].nodeValue !];
|
||||
}
|
||||
}
|
||||
return asArray || [];
|
||||
|
@ -113,7 +113,7 @@ export class UpgradeAdapter {
|
||||
private upgradedProviders: Provider[] = [];
|
||||
private ngZone: NgZone;
|
||||
private ng1Module: angular.IModule;
|
||||
private moduleRef: NgModuleRef<any> = null;
|
||||
private moduleRef: NgModuleRef<any>|null = null;
|
||||
private ng2BootstrapDeferred: Deferred<angular.IInjectorService>;
|
||||
|
||||
constructor(private ng2AppModule: Type<any>, private compilerOptions?: CompilerOptions) {
|
||||
@ -382,7 +382,7 @@ export class UpgradeAdapter {
|
||||
const windowAngular = (window as any /** TODO #???? */)['angular'];
|
||||
windowAngular.resumeBootstrap = undefined;
|
||||
|
||||
this.ngZone.run(() => { angular.bootstrap(element, [this.ng1Module.name], config); });
|
||||
this.ngZone.run(() => { angular.bootstrap(element, [this.ng1Module.name], config !); });
|
||||
const ng1BootstrapPromise = new Promise((resolve) => {
|
||||
if (windowAngular.resumeBootstrap) {
|
||||
const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
|
||||
@ -397,8 +397,8 @@ export class UpgradeAdapter {
|
||||
});
|
||||
|
||||
Promise.all([this.ng2BootstrapDeferred.promise, ng1BootstrapPromise]).then(([ng1Injector]) => {
|
||||
angular.element(element).data(controllerKey(INJECTOR_KEY), this.moduleRef.injector);
|
||||
this.moduleRef.injector.get(NgZone).run(
|
||||
angular.element(element).data !(controllerKey(INJECTOR_KEY), this.moduleRef !.injector);
|
||||
this.moduleRef !.injector.get(NgZone).run(
|
||||
() => { (<any>upgrade)._bootstrapDone(this.moduleRef, ng1Injector); });
|
||||
}, onError);
|
||||
return upgrade;
|
||||
@ -494,9 +494,9 @@ export class UpgradeAdapter {
|
||||
|
||||
this.ngZone = new NgZone({enableLongStackTrace: Zone.hasOwnProperty('longStackTraceZoneSpec')});
|
||||
this.ng2BootstrapDeferred = new Deferred();
|
||||
ng1Module.factory(INJECTOR_KEY, () => this.moduleRef.injector.get(Injector))
|
||||
ng1Module.factory(INJECTOR_KEY, () => this.moduleRef !.injector.get(Injector))
|
||||
.constant(NG_ZONE_KEY, this.ngZone)
|
||||
.factory(COMPILER_KEY, () => this.moduleRef.injector.get(Compiler))
|
||||
.factory(COMPILER_KEY, () => this.moduleRef !.injector.get(Compiler))
|
||||
.config([
|
||||
'$provide', '$injector',
|
||||
(provide: angular.IProvideService, ng1Injector: angular.IInjectorService) => {
|
||||
@ -524,7 +524,7 @@ export class UpgradeAdapter {
|
||||
const newWhenStable = function(callback: Function) {
|
||||
originalWhenStable.call(this, function() {
|
||||
const ng2Testability: Testability =
|
||||
upgradeAdapter.moduleRef.injector.get(Testability);
|
||||
upgradeAdapter.moduleRef !.injector.get(Testability);
|
||||
if (ng2Testability.isStable()) {
|
||||
callback.apply(this, arguments);
|
||||
} else {
|
||||
@ -601,7 +601,7 @@ class ParentInjectorPromise {
|
||||
|
||||
constructor(private element: angular.IAugmentedJQuery) {
|
||||
// store the promise on the element
|
||||
element.data(controllerKey(INJECTOR_KEY), this);
|
||||
element.data !(controllerKey(INJECTOR_KEY), this);
|
||||
}
|
||||
|
||||
then(callback: (injector: Injector) => any) {
|
||||
@ -616,10 +616,10 @@ class ParentInjectorPromise {
|
||||
this.injector = injector;
|
||||
|
||||
// reset the element data to point to the real injector
|
||||
this.element.data(controllerKey(INJECTOR_KEY), injector);
|
||||
this.element.data !(controllerKey(INJECTOR_KEY), injector);
|
||||
|
||||
// clean out the element to prevent memory leaks
|
||||
this.element = null;
|
||||
this.element = null !;
|
||||
|
||||
// run all the queued callbacks
|
||||
this.callbacks.forEach((callback) => callback(injector));
|
||||
@ -635,12 +635,12 @@ class ParentInjectorPromise {
|
||||
*/
|
||||
export class UpgradeAdapterRef {
|
||||
/* @internal */
|
||||
private _readyFn: (upgradeAdapterRef?: UpgradeAdapterRef) => void = null;
|
||||
private _readyFn: ((upgradeAdapterRef?: UpgradeAdapterRef) => void)|null = null;
|
||||
|
||||
public ng1RootScope: angular.IRootScopeService = null;
|
||||
public ng1Injector: angular.IInjectorService = null;
|
||||
public ng2ModuleRef: NgModuleRef<any> = null;
|
||||
public ng2Injector: Injector = null;
|
||||
public ng1RootScope: angular.IRootScopeService = null !;
|
||||
public ng1Injector: angular.IInjectorService = null !;
|
||||
public ng2ModuleRef: NgModuleRef<any> = null !;
|
||||
public ng2Injector: Injector = null !;
|
||||
|
||||
/* @internal */
|
||||
private _bootstrapDone(ngModuleRef: NgModuleRef<any>, ng1Injector: angular.IInjectorService) {
|
||||
@ -658,13 +658,13 @@ export class UpgradeAdapterRef {
|
||||
* The `ready` callback function is invoked inside the Angular zone, therefore it does not
|
||||
* require a call to `$apply()`.
|
||||
*/
|
||||
public ready(fn: (upgradeAdapterRef?: UpgradeAdapterRef) => void) { this._readyFn = fn; }
|
||||
public ready(fn: (upgradeAdapterRef: UpgradeAdapterRef) => void) { this._readyFn = fn; }
|
||||
|
||||
/**
|
||||
* Dispose of running hybrid AngularJS / Angular application.
|
||||
*/
|
||||
public dispose() {
|
||||
this.ng1Injector.get($ROOT_SCOPE).$destroy();
|
||||
this.ng2ModuleRef.destroy();
|
||||
this.ng1Injector !.get($ROOT_SCOPE).$destroy();
|
||||
this.ng2ModuleRef !.destroy();
|
||||
}
|
||||
}
|
||||
|
@ -44,30 +44,32 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||
propertyOutputs: string[] = [];
|
||||
checkProperties: string[] = [];
|
||||
propertyMap: {[name: string]: string} = {};
|
||||
linkFn: angular.ILinkFn = null;
|
||||
directive: angular.IDirective = null;
|
||||
$controller: angular.IControllerService = null;
|
||||
linkFn: angular.ILinkFn|null = null;
|
||||
directive: angular.IDirective|null = null;
|
||||
$controller: angular.IControllerService|null = null;
|
||||
|
||||
constructor(public name: string) {
|
||||
const selector = name.replace(
|
||||
CAMEL_CASE, (all: any /** TODO #9100 */, next: string) => '-' + next.toLowerCase());
|
||||
const self = this;
|
||||
this.type =
|
||||
Directive({selector: selector, inputs: this.inputsRename, outputs: this.outputsRename})
|
||||
.Class({
|
||||
constructor: [
|
||||
new Inject($SCOPE), ElementRef,
|
||||
function(scope: angular.IScope, elementRef: ElementRef) {
|
||||
return new UpgradeNg1ComponentAdapter(
|
||||
self.linkFn, scope, self.directive, elementRef, self.$controller, self.inputs,
|
||||
self.outputs, self.propertyOutputs, self.checkProperties, self.propertyMap);
|
||||
}
|
||||
],
|
||||
ngOnInit: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
ngOnChanges: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
ngDoCheck: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
ngOnDestroy: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
});
|
||||
this.type = Directive({
|
||||
selector: selector,
|
||||
inputs: this.inputsRename,
|
||||
outputs: this.outputsRename
|
||||
}).Class({
|
||||
constructor: [
|
||||
new Inject($SCOPE), ElementRef,
|
||||
function(scope: angular.IScope, elementRef: ElementRef) {
|
||||
return new UpgradeNg1ComponentAdapter(
|
||||
self.linkFn !, scope, self.directive !, elementRef, self.$controller !, self.inputs,
|
||||
self.outputs, self.propertyOutputs, self.checkProperties, self.propertyMap);
|
||||
}
|
||||
],
|
||||
ngOnInit: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
ngOnChanges: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
ngDoCheck: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
ngOnDestroy: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||
});
|
||||
}
|
||||
|
||||
extractDirective(injector: angular.IInjectorService): angular.IDirective {
|
||||
@ -90,13 +92,13 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||
}
|
||||
|
||||
extractBindings() {
|
||||
const btcIsObject = typeof this.directive.bindToController === 'object';
|
||||
if (btcIsObject && Object.keys(this.directive.scope).length) {
|
||||
const btcIsObject = typeof this.directive !.bindToController === 'object';
|
||||
if (btcIsObject && Object.keys(this.directive !.scope).length) {
|
||||
throw new Error(
|
||||
`Binding definitions on scope and controller at the same time are not supported.`);
|
||||
}
|
||||
|
||||
const context = (btcIsObject) ? this.directive.bindToController : this.directive.scope;
|
||||
const context = (btcIsObject) ? this.directive !.bindToController : this.directive !.scope;
|
||||
|
||||
if (typeof context == 'object') {
|
||||
for (const name in context) {
|
||||
@ -147,14 +149,15 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||
|
||||
compileTemplate(
|
||||
compile: angular.ICompileService, templateCache: angular.ITemplateCacheService,
|
||||
httpBackend: angular.IHttpBackendService): Promise<angular.ILinkFn> {
|
||||
if (this.directive.template !== undefined) {
|
||||
httpBackend: angular.IHttpBackendService): Promise<angular.ILinkFn>|null {
|
||||
if (this.directive !.template !== undefined) {
|
||||
this.linkFn = compileHtml(
|
||||
isFunction(this.directive.template) ? this.directive.template() :
|
||||
this.directive.template);
|
||||
} else if (this.directive.templateUrl) {
|
||||
const url = isFunction(this.directive.templateUrl) ? this.directive.templateUrl() :
|
||||
this.directive.templateUrl;
|
||||
isFunction(this.directive !.template) ? (this.directive !.template as Function)() :
|
||||
this.directive !.template);
|
||||
} else if (this.directive !.templateUrl) {
|
||||
const url = isFunction(this.directive !.templateUrl) ?
|
||||
(this.directive !.templateUrl as Function)() :
|
||||
this.directive !.templateUrl;
|
||||
const html = templateCache.get(url);
|
||||
if (html !== undefined) {
|
||||
this.linkFn = compileHtml(html);
|
||||
@ -200,7 +203,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||
exportedComponent.$controller = $controller;
|
||||
exportedComponent.extractBindings();
|
||||
const promise: Promise<angular.ILinkFn> =
|
||||
exportedComponent.compileTemplate(compile, templateCache, httpBackend);
|
||||
exportedComponent.compileTemplate(compile, templateCache, httpBackend) !;
|
||||
if (promise) promises.push(promise);
|
||||
}
|
||||
}
|
||||
@ -209,8 +212,8 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
||||
}
|
||||
|
||||
class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
private controllerInstance: IControllerInstance = null;
|
||||
destinationObj: IBindingDestination = null;
|
||||
private controllerInstance: IControllerInstance|null = null;
|
||||
destinationObj: IBindingDestination|null = null;
|
||||
checkLastValues: any[] = [];
|
||||
componentScope: angular.IScope;
|
||||
element: Element;
|
||||
@ -261,7 +264,7 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
if (link) {
|
||||
const attrs: angular.IAttributes = NOT_SUPPORTED;
|
||||
const transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
|
||||
const linkController = this.resolveRequired(this.$element, this.directive.require);
|
||||
const linkController = this.resolveRequired(this.$element, this.directive.require !);
|
||||
(<angular.IDirectiveLinkFn>this.directive.link)(
|
||||
this.componentScope, this.$element, attrs, linkController, transcludeFn);
|
||||
}
|
||||
@ -273,8 +276,8 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
childNodes.push(childNode);
|
||||
}
|
||||
this.linkFn(this.componentScope, (clonedElement, scope) => {
|
||||
for (let i = 0, ii = clonedElement.length; i < ii; i++) {
|
||||
this.element.appendChild(clonedElement[i]);
|
||||
for (let i = 0, ii = clonedElement !.length; i < ii; i++) {
|
||||
this.element.appendChild(clonedElement ![i]);
|
||||
}
|
||||
}, {
|
||||
parentBoundTranscludeFn: (scope: any /** TODO #9100 */,
|
||||
@ -294,8 +297,8 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
ng1Changes[this.propertyMap[name]] = change;
|
||||
});
|
||||
|
||||
if (isFunction(this.destinationObj.$onChanges)) {
|
||||
this.destinationObj.$onChanges(ng1Changes);
|
||||
if (isFunction(this.destinationObj !.$onChanges)) {
|
||||
this.destinationObj !.$onChanges !(ng1Changes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,7 +307,7 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
const lastValues = this.checkLastValues;
|
||||
const checkProperties = this.checkProperties;
|
||||
for (let i = 0; i < checkProperties.length; i++) {
|
||||
const value = destinationObj[checkProperties[i]];
|
||||
const value = destinationObj ![checkProperties[i]];
|
||||
const last = lastValues[i];
|
||||
if (value !== last) {
|
||||
if (typeof value == 'number' && isNaN(value) && typeof last == 'number' && isNaN(last)) {
|
||||
@ -328,14 +331,14 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
}
|
||||
|
||||
setComponentProperty(name: string, value: any) {
|
||||
this.destinationObj[this.propertyMap[name]] = value;
|
||||
this.destinationObj ![this.propertyMap[name]] = value;
|
||||
}
|
||||
|
||||
private buildController(controllerType: any /** TODO #9100 */) {
|
||||
const locals = {$scope: this.componentScope, $element: this.$element};
|
||||
const controller: any =
|
||||
this.$controller(controllerType, locals, null, this.directive.controllerAs);
|
||||
this.$element.data(controllerKey(this.directive.name), controller);
|
||||
this.$element.data(controllerKey(this.directive.name !), controller);
|
||||
return controller;
|
||||
}
|
||||
|
||||
@ -362,8 +365,8 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
}
|
||||
|
||||
const key = controllerKey(name);
|
||||
if (startParent) $element = $element.parent();
|
||||
const dep = searchParents ? $element.inheritedData(key) : $element.data(key);
|
||||
if (startParent) $element = $element.parent !();
|
||||
const dep = searchParents ? $element.inheritedData !(key) : $element.data !(key);
|
||||
if (!dep && !isOptional) {
|
||||
throw new Error(`Can not locate '${require}' in '${this.directive.name}'.`);
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ import * as angular from '../common/angular1';
|
||||
// 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
|
||||
// the stored injector and release the reference to it.
|
||||
let tempInjectorRef: angular.IInjectorService;
|
||||
let tempInjectorRef: angular.IInjectorService|null;
|
||||
export function setTempInjectorRef(injector: angular.IInjectorService) {
|
||||
tempInjectorRef = injector;
|
||||
}
|
||||
export function injectorFactory() {
|
||||
const injector: angular.IInjectorService = tempInjectorRef;
|
||||
const injector: angular.IInjectorService|null = tempInjectorRef;
|
||||
tempInjectorRef = null; // clear the value to prevent memory leaks
|
||||
return injector;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
|
||||
// We will be instantiating the controller in the `ngOnInit` hook, when the first `ngOnChanges`
|
||||
// will have been already triggered. We store the `SimpleChanges` and "play them back" later.
|
||||
private pendingChanges: SimpleChanges;
|
||||
private pendingChanges: SimpleChanges|null;
|
||||
|
||||
private unregisterDoCheckWatcher: Function;
|
||||
|
||||
@ -152,7 +152,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
const bindToController = this.directive.bindToController;
|
||||
if (controllerType) {
|
||||
this.controllerInstance = this.buildController(
|
||||
controllerType, this.$componentScope, this.$element, this.directive.controllerAs);
|
||||
controllerType, this.$componentScope, this.$element, this.directive.controllerAs !);
|
||||
} else if (bindToController) {
|
||||
throw new Error(
|
||||
`Upgraded directive '${this.directive.name}' specifies 'bindToController' but no controller.`);
|
||||
@ -165,7 +165,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
// Require other controllers
|
||||
const directiveRequire = this.getDirectiveRequire(this.directive);
|
||||
const requiredControllers =
|
||||
this.resolveRequire(this.directive.name, this.$element, directiveRequire);
|
||||
this.resolveRequire(this.directive.name !, this.$element, directiveRequire);
|
||||
|
||||
if (this.directive.bindToController && isMap(directiveRequire)) {
|
||||
const requiredControllersMap = requiredControllers as{[key: string]: IControllerInstance};
|
||||
@ -187,7 +187,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
|
||||
// Hook: $doCheck
|
||||
if (this.controllerInstance && isFunction(this.controllerInstance.$doCheck)) {
|
||||
const callDoCheck = () => this.controllerInstance.$doCheck();
|
||||
const callDoCheck = () => this.controllerInstance.$doCheck !();
|
||||
|
||||
this.unregisterDoCheckWatcher = this.$componentScope.$parent.$watch(callDoCheck);
|
||||
callDoCheck();
|
||||
@ -204,8 +204,8 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
}
|
||||
|
||||
const attachChildNodes: angular.ILinkFn = (scope, cloneAttach) =>
|
||||
cloneAttach(contentChildNodes);
|
||||
linkFn(this.$componentScope, null, {parentBoundTranscludeFn: attachChildNodes});
|
||||
cloneAttach !(contentChildNodes);
|
||||
linkFn(this.$componentScope, null !, {parentBoundTranscludeFn: attachChildNodes});
|
||||
|
||||
if (postLink) {
|
||||
postLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
|
||||
@ -272,12 +272,12 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
}
|
||||
|
||||
private getDirectiveRequire(directive: angular.IDirective): angular.DirectiveRequireProperty {
|
||||
const require = directive.require || (directive.controller && directive.name);
|
||||
const require = directive.require || (directive.controller && directive.name) !;
|
||||
|
||||
if (isMap(require)) {
|
||||
Object.keys(require).forEach(key => {
|
||||
const value = require[key];
|
||||
const match = value.match(REQUIRE_PREFIX_RE);
|
||||
const match = value.match(REQUIRE_PREFIX_RE) !;
|
||||
const name = value.substring(match[0].length);
|
||||
|
||||
if (!name) {
|
||||
@ -335,7 +335,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
|
||||
private extractChildNodes(element: Element): Node[] {
|
||||
const childNodes: Node[] = [];
|
||||
let childNode: Node;
|
||||
let childNode: Node|null;
|
||||
|
||||
while (childNode = element.firstChild) {
|
||||
element.removeChild(childNode);
|
||||
@ -377,13 +377,14 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
// Quoted properties below so that this code can be optimized with Closure Compiler.
|
||||
const locals = {'$scope': $scope, '$element': $element};
|
||||
const controller = this.$controller(controllerType, locals, null, controllerAs);
|
||||
$element.data(controllerKey(this.directive.name), controller);
|
||||
$element.data !(controllerKey(this.directive.name !), controller);
|
||||
return controller;
|
||||
}
|
||||
|
||||
private resolveRequire(
|
||||
directiveName: string, $element: angular.IAugmentedJQuery,
|
||||
require: angular.DirectiveRequireProperty): angular.SingleOrListOrMap<IControllerInstance> {
|
||||
require: angular.DirectiveRequireProperty):
|
||||
angular.SingleOrListOrMap<IControllerInstance>|null {
|
||||
if (!require) {
|
||||
return null;
|
||||
} else if (Array.isArray(require)) {
|
||||
@ -392,11 +393,11 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
const value: {[key: string]: IControllerInstance} = {};
|
||||
|
||||
Object.keys(require).forEach(
|
||||
key => value[key] = this.resolveRequire(directiveName, $element, require[key]));
|
||||
key => value[key] = this.resolveRequire(directiveName, $element, require[key]) !);
|
||||
|
||||
return value;
|
||||
} else if (typeof require === 'string') {
|
||||
const match = require.match(REQUIRE_PREFIX_RE);
|
||||
const match = require.match(REQUIRE_PREFIX_RE) !;
|
||||
const inheritType = match[1] || match[3];
|
||||
|
||||
const name = require.substring(match[0].length);
|
||||
@ -407,10 +408,10 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
|
||||
const ctrlKey = controllerKey(name);
|
||||
|
||||
if (startOnParent) {
|
||||
$element = $element.parent();
|
||||
$element = $element.parent !();
|
||||
}
|
||||
|
||||
const value = searchParents ? $element.inheritedData(ctrlKey) : $element.data(ctrlKey);
|
||||
const value = searchParents ? $element.inheritedData !(ctrlKey) : $element.data !(ctrlKey);
|
||||
|
||||
if (!value && !isOptional) {
|
||||
throw new Error(
|
||||
|
@ -202,7 +202,7 @@ export class UpgradeModule {
|
||||
this.injector.get($INJECTOR);
|
||||
|
||||
// Put the injector on the DOM, so that it can be "required"
|
||||
angular.element(element).data(controllerKey(INJECTOR_KEY), this.injector);
|
||||
angular.element(element).data !(controllerKey(INJECTOR_KEY), this.injector);
|
||||
|
||||
// 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
|
||||
|
Reference in New Issue
Block a user