refactor(NgUpgrade): remove deprecated addProvider

BREAKING CHANGE: previously deprecated UpgradeAdapter#addProvider was removed, see deprecation notice for migration instructions.
This commit is contained in:
Igor Minar 2016-08-12 12:30:08 -07:00 committed by Vikram Subramanian
parent d2825077b1
commit 12b0a3d0e5
3 changed files with 7 additions and 49 deletions

View File

@ -450,49 +450,6 @@ export class UpgradeAdapter {
return upgrade; return upgrade;
} }
/**
* Adds a provider to the top level environment of a hybrid AngularJS v1 / Angular v2 application.
*
* In hybrid AngularJS v1 / Angular v2 application, there is no one root Angular v2 component,
* for this reason we provide an application global way of registering providers which is
* consistent with single global injection in AngularJS v1.
*
* ### Example
*
* ```
* class Greeter {
* greet(name) {
* alert('Hello ' + name + '!');
* }
* }
*
* @Component({
* selector: 'app',
* template: ''
* })
* class App {
* constructor(greeter: Greeter) {
* this.greeter('World');
* }
* }
*
* var adapter = new UpgradeAdapter();
* adapter.addProvider(Greeter);
*
* var module = angular.module('myExample', []);
* module.directive('app', adapter.downgradeNg2Component(App));
*
* document.body.innerHTML = '<app></app>'
* adapter.bootstrap(document.body, ['myExample']);
*```
*
* @deprecated Use NgModules and `new UpgradeAdapter(ng2AppModule)` to configure top-level
*providers
*/
public addProvider(provider: Type<any>|Provider|any[]|any): void {
this.providers.push(provider);
}
/** /**
* Allows AngularJS v1 service to be accessible from Angular v2. * Allows AngularJS v1 service to be accessible from Angular v2.
* *

View File

@ -836,16 +836,18 @@ export function main() {
describe('injection', () => { describe('injection', () => {
function SomeToken() {} function SomeToken() {}
it('should export ng2 instance to ng1', it('should export ng2 instance to ng1', async(() => {
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { var MyModule = NgModule({
var adapter = new UpgradeAdapter(); providers: [{provide: SomeToken, useValue: 'correct_value'}],
imports: [BrowserModule]
}).Class({constructor: function() {}});
var adapter = new UpgradeAdapter(MyModule);
var module = angular.module('myExample', []); var module = angular.module('myExample', []);
adapter.addProvider({provide: SomeToken, useValue: 'correct_value'});
module.factory('someToken', adapter.downgradeNg2Provider(SomeToken)); module.factory('someToken', adapter.downgradeNg2Provider(SomeToken));
adapter.bootstrap(html('<div>'), ['myExample']).ready((ref) => { adapter.bootstrap(html('<div>'), ['myExample']).ready((ref) => {
expect(ref.ng1Injector.get('someToken')).toBe('correct_value'); expect(ref.ng1Injector.get('someToken')).toBe('correct_value');
ref.dispose(); ref.dispose();
async.done();
}); });
})); }));

View File

@ -1,7 +1,6 @@
/** @experimental */ /** @experimental */
export declare class UpgradeAdapter { export declare class UpgradeAdapter {
constructor(ng2AppModule?: Type<any>); constructor(ng2AppModule?: Type<any>);
/** @deprecated */ addProvider(provider: Type<any> | Provider | any[] | any): void;
bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig): UpgradeAdapterRef; bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig): UpgradeAdapterRef;
downgradeNg2Component(type: Type<any>): Function; downgradeNg2Component(type: Type<any>): Function;
downgradeNg2Provider(token: any): Function; downgradeNg2Provider(token: any): Function;