feat(upgrade): allow setting the angularjs lib at runtime (#15168)

This PR adds an ability to reset the angularjs library, which is often needed when Angular
is loaded lazily using RequireJS.
This commit is contained in:
Victor Savkin
2017-04-14 12:04:28 -04:00
committed by Tobias Bosch
parent 65af9641c2
commit 8ad464d90e
4 changed files with 87 additions and 16 deletions

View File

@ -12,7 +12,7 @@ import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import * as angular from '@angular/upgrade/src/common/angular1';
import {$INJECTOR, INJECTOR_KEY} from '@angular/upgrade/src/common/constants';
import {UpgradeModule, downgradeInjectable} from '@angular/upgrade/static';
import {UpgradeModule, downgradeInjectable, getAngularLib, setAngularLib} from '@angular/upgrade/static';
import {bootstrap, html} from '../test_helpers';
@ -99,5 +99,33 @@ export function main() {
expect(runBlockTriggered).toBeTruthy();
});
}));
it('should allow resetting angular at runtime', async(() => {
let wrappedBootstrapepedCalled = false;
const n: any = getAngularLib();
setAngularLib({
bootstrap: (...args: any[]) => {
wrappedBootstrapepedCalled = true;
n.bootstrap(...args);
},
module: n.module,
element: n.element,
version: n.version,
resumeBootstrap: n.resumeBootstrap,
getTestability: n.getTestability
});
@NgModule({imports: [BrowserModule, UpgradeModule]})
class Ng2Module {
ngDoBootstrap() {}
}
const ng1Module = angular.module('ng1Module', []);
bootstrap(platformBrowserDynamic(), Ng2Module, html('<div>'), ng1Module)
.then((upgrade) => { expect(wrappedBootstrapepedCalled).toEqual(true); });
}));
});
}