angular-cn/modules/angular2/src/core/application_ref.ts
Jeff Cross f14b212dc9 refactor: export core APIs from angular2/core
This change moves many APIs to the angular2/core export.

This change also automatically adds FORM_BINDINGS in
the application root injector.

BREAKING CHANGE:
    Many dependencies that were previously exported from specific
    APIs are now exported from angular2/core. Affected exports, which
    should now be included from angular2/core include:

    angular2/forms
    angular2/di
    angular2/directives
    angular2/change_detection
    angular2/bootstrap (except for dart users)
    angular2/render
    angular2/metadata
    angular2/debug
    angular2/pipes
Closes #3977
2015-09-05 07:01:34 +00:00

48 lines
1.3 KiB
TypeScript

import {ComponentRef} from 'angular2/src/core/compiler/dynamic_component_loader';
import {Injector} from 'angular2/src/core/di';
import {Type} from 'angular2/src/core/facade/lang';
/**
* Represents a Angular's representation of an Application.
*
* `ApplicationRef` represents a running application instance. Use it to retrieve the host
* component, injector,
* or dispose of an application.
*/
export class ApplicationRef {
_hostComponent: ComponentRef;
_injector: Injector;
_hostComponentType: Type;
/**
* @private
*/
constructor(hostComponent: ComponentRef, hostComponentType: Type, injector: Injector) {
this._hostComponent = hostComponent;
this._injector = injector;
this._hostComponentType = hostComponentType;
}
/**
* Returns the current {@link ComponentMetadata} type.
*/
get hostComponentType(): Type { return this._hostComponentType; }
/**
* Returns the current {@link ComponentMetadata} instance.
*/
get hostComponent(): any { return this._hostComponent.instance; }
/**
* Dispose (un-load) the application.
*/
dispose(): void {
// TODO: We also need to clean up the Zone, ... here!
this._hostComponent.dispose();
}
/**
* Returns the root application {@link Injector}.
*/
get injector(): Injector { return this._injector; }
}