ViewContainerRef
class ViewContainerRef { get element(): ElementRef get injector(): Injector get parentInjector(): Injector clear(): void get(index: number): ViewRef|null get length(): number createEmbeddedView<C>(templateRef: TemplateRef<C>,context?: C,index?: number): EmbeddedViewRef<C> createComponent<C>(componentFactory: ComponentFactory<C>,index?: number,injector?: Injector,projectableNodes?: any[][],ngModule?: NgModuleRef<any>): ComponentRef<C> insert(viewRef: ViewRef,index?: number): ViewRef move(viewRef: ViewRef,currentIndex: number): ViewRef indexOf(viewRef: ViewRef): number remove(index?: number): void detach(index?: number): ViewRef|null }
描述Represents a container where one or more Views can be attached. The container can contain two kinds of Views. Host Views,created by instantiating a Component via createComponent,and Embedded Views,created by instantiating an Embedded Template via createEmbeddedView. 容器可以包含两种视图。 The location of the View Container within the containing View is specified by the Anchor element. Each View Container can have only one Anchor Element and each Anchor Element can only have a single View Container. Root elements of Views attached to this container become siblings of the Anchor Element in the Rendered View. To access a ViewContainerRef of an Element,you can either place a Directive injected with ViewContainerRef on the Element,or you obtain it via a ViewChild query. 方法成员
Anchor element that specifies the location of this container in the containing View.
Destroys all Views in this container.
Returns the ViewRef for the View located in this container at the specified index.
Returns the number of Views currently attached to this container.
Instantiates an Embedded View based on the 基于“templateRef”实例化嵌入式视图,并将其插入到指定索引的此容器中。 If index is not specified,the new View will be inserted as the last View in the container. Returns the ViewRef for the newly created View.
Instantiates a single Component and inserts its Host View into this container at the specified index. The component is instantiated using its ComponentFactory which can be obtained via ComponentFactoryResolver. If index is not specified,the new View will be inserted as the last View in the container. You can optionally specify the Injector that will be used as parent for the Component. Returns the ComponentRef of the Host View created for the newly instantiated Component.
Inserts a View identified by a ViewRef into the container at the specified index. If index is not specified,the new View will be inserted as the last View in the container. Returns the inserted ViewRef.
Moves a View identified by a ViewRef into the container at the specified index. Returns the inserted ViewRef. indexOf(viewRef: ViewRef): number
Destroys a View attached to this container at the specified index. If index is not specified,the last View in the container will be removed.
Use along with insert to move a View within the current container. If the index param is omitted,the last ViewRef is detached. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |