Angular2 upgradeAdapter not working with $rootScope, $state etc

Viewed 667

Im trying to upgrade an Angular1 application with the help of Angular2's upgradeAdapter. The app is bootstrapped with the upgradeAdapter and works as expected, at least as long as I don't try to upgrade one of A1's integrated services.

Let's say i have this A1 Service written in typescript:

//A1.ts
// inject decorator that in short does target.$inject = ...injects
@Inject('$rootScope')
class TestService{
    constructor($rootScope: angular.IRootScopeService){
        //$rootScope.whatever();
    }
} 
// register the service in application module
globalModule.service('TestService', TestService);

I can inject the TestService the normal A1 way wherever I need to, and it works.

Now for the A2 upgrade i do:

//upgradeAdapter.ts
import {UpgradeAdapter} from 'angular2/upgrade';
const upgradeAdapter = new UpgradeAdapter();
export default upgradeAdapter;

//A2.ts
import upgradeAdapter from './upgradeAdapter'
import { Injectable, Inject} from 'angular2/core'

@Injectable()
export class A2TestService{
    constructor(@Inject('$rootScope') _rootScope: angular.IRootScope){
        //_rootScope.whatever()
    }
}

upgradeAdapter.upgradeNG1Provider('$rootScope');
// tried with additional upgradeAdapter.upgradeNG1Provider('$rootScopeProvider');
upgradeAdapter.addProvider(A2TestService);
// make this service available in A1 World
globalModule.service('A2TestService',upgradeAdapter.downgradeNG2Provider(A2TestService));

Hybrid DI works when upgrading with this formula, as long as I don't use, e.g., $rootScope like above. Then I am getting

"Error during instantiation of $rootScope!  (A2TestService -> $rootScope)
Stacktrace: Type Error: Cannot read property 'get' of null 
 at provider.push.core_1.provide.useFactory (upgrade.js: 684)
..."

coming from angular2.js (on beta.9)

What are my options here?

0 Answers
Related