AppViewManager

export class AppViewManager

exported from angular2/core defined in angular2/src/core/linker/view_manager.ts (line 26)

Service exposing low level API for creating, moving and destroying Views.

Most applications should use higher-level abstractions like DynamicComponentLoader and ViewContainerRef instead.

Members

getViewContainer(location: ElementRef) : ViewContainerRef

Returns a ViewContainerRef of the View Container at the specified location.

getHostElement(hostViewRef: HostViewRef) : ElementRef

Returns the ElementRef that makes up the specified Host View.

getNamedElementInComponentView(hostLocation: ElementRef, variableName: string) : ElementRef

Searches the Component View of the Component specified via hostLocation and returns the ElementRef for the Element identified via a Variable Name variableName.

Throws an exception if the specified hostLocation is not a Host Element of a Component, or if variable variableName couldn't be found in the Component View of this Component.

getComponent(hostLocation: ElementRef) : any

Returns the component instance for the provided Host Element.

createRootHostView(hostProtoViewRef: ProtoViewRef, overrideSelector: string, injector: Injector) : HostViewRef

Creates an instance of a Component and attaches it to the first element in the global View (usually DOM Document) that matches the component's selector or overrideSelector.

This as a low-level way to bootstrap an application and upgrade an existing Element to a Host Element. Most applications should use DynamicComponentLoader instead.

The Component and its View are created based on the hostProtoViewRef which can be obtained by compiling the component with Compiler.

Use AppViewManager to destroy the created Component and it's Host View.

#

@ng.Component({ selector: 'child-component' }) @ng.View({ template: 'Child' }) class ChildComponent { } @ng.Component({ selector: 'my-app' }) @ng.View({ template: ` Parent (<some-component></some-component>) ` }) class MyApp implements OnDestroy { viewRef: ng.ViewRef; constructor(public appViewManager: ng.AppViewManager, compiler: ng.Compiler) { compiler.compileInHost(ChildComponent).then((protoView: ng.ProtoViewRef) => { this.viewRef = appViewManager.createRootHostView(protoView, 'some-component', null); }) } ngOnDestroy() { this.appViewManager.destroyRootHostView(this.viewRef); this.viewRef = null; } } ng.bootstrap(MyApp);

destroyRootHostView(hostViewRef: HostViewRef)

Destroys the Host View created via AppViewManager.

Along with the Host View, the Component Instance as well as all nested View and Components are destroyed as well.

createEmbeddedViewInContainer(viewContainerLocation: ElementRef, index: number, templateRef: TemplateRef) : ViewRef

Instantiates an Embedded View based on the templateRef and inserts it into the View Container specified via viewContainerLocation at the specified index.

Returns the ViewRef for the newly created View.

This as a low-level way to create and attach an Embedded via to a View Container. Most applications should used ViewContainerRef instead.

Use AppViewManager to destroy the created Embedded View.

createHostViewInContainer(viewContainerLocation: ElementRef, index: number, protoViewRef: ProtoViewRef, imperativelyCreatedInjector: ResolvedProvider[]) : HostViewRef

Instantiates a single Component and inserts its Host View into the View Container found at viewContainerLocation. Within the container, the view will be inserted at position specified via index.

The component is instantiated using its protoViewRef which can be obtained via Compiler.

You can optionally specify imperativelyCreatedInjector, which configure the Injector that will be created for the Host View.

Returns the HostViewRef of the Host View created for the newly instantiated Component.

Use AppViewManager to destroy the created Host View.

destroyViewInContainer(viewContainerLocation: ElementRef, index: number)

Destroys an Embedded or Host View attached to a View Container at the specified index.

The View Container is located via viewContainerLocation.

attachViewInContainer(viewContainerLocation: ElementRef, index: number, viewRef: ViewRef) : ViewRef

See AppViewManager.

detachViewInContainer(viewContainerLocation: ElementRef, index: number) : ViewRef

See AppViewManager.