From cbc8d0adf8e04d2ebbf00d403b82f8c59ece6da0 Mon Sep 17 00:00:00 2001 From: Matthew Windwer Date: Thu, 26 May 2016 14:58:47 -0400 Subject: [PATCH] fix(upgrade): Ensure upgrade adapter works on angular.js 1.2 (#8647) --- .../@angular/upgrade/src/upgrade_adapter.ts | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/@angular/upgrade/src/upgrade_adapter.ts b/modules/@angular/upgrade/src/upgrade_adapter.ts index eef14e296d..5ab170df24 100644 --- a/modules/@angular/upgrade/src/upgrade_adapter.ts +++ b/modules/@angular/upgrade/src/upgrade_adapter.ts @@ -319,7 +319,8 @@ export class UpgradeAdapter { .value(NG2_COMPONENT_FACTORY_REF_MAP, componentFactoryRefMap) .config([ '$provide', - (provide) => { + '$injector', + (provide, ng1Injector) => { provide.decorator(NG1_ROOT_SCOPE, [ '$delegate', function(rootScopeDelegate: angular.IRootScopeService) { @@ -333,27 +334,29 @@ export class UpgradeAdapter { return rootScope = rootScopeDelegate; } ]); - provide.decorator(NG1_TESTABILITY, [ - '$delegate', - function(testabilityDelegate: angular.ITestabilityService) { - var ng2Testability: Testability = injector.get(Testability); + if (ng1Injector.has(NG1_TESTABILITY)) { + provide.decorator(NG1_TESTABILITY, [ + '$delegate', + function(testabilityDelegate: angular.ITestabilityService) { + var ng2Testability: Testability = injector.get(Testability); - var origonalWhenStable: Function = testabilityDelegate.whenStable; - var newWhenStable = (callback: Function): void => { - var whenStableContext: any = this; - origonalWhenStable.call(this, function() { - if (ng2Testability.isStable()) { - callback.apply(this, arguments); - } else { - ng2Testability.whenStable(newWhenStable.bind(whenStableContext, callback)); - } - }); - }; + var origonalWhenStable: Function = testabilityDelegate.whenStable; + var newWhenStable = (callback: Function): void => { + var whenStableContext: any = this; + origonalWhenStable.call(this, function() { + if (ng2Testability.isStable()) { + callback.apply(this, arguments); + } else { + ng2Testability.whenStable(newWhenStable.bind(whenStableContext, callback)); + } + }); + }; - testabilityDelegate.whenStable = newWhenStable; - return testabilityDelegate; - } - ]); + testabilityDelegate.whenStable = newWhenStable; + return testabilityDelegate; + } + ]); + } } ]);