本文整理汇总了TypeScript中@angular/core.ComponentResolver.resolveComponent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ComponentResolver.resolveComponent方法的具体用法?TypeScript ComponentResolver.resolveComponent怎么用?TypeScript ComponentResolver.resolveComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/core.ComponentResolver
的用法示例。
在下文中一共展示了ComponentResolver.resolveComponent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: render
render(type: Type,
viewContainer: ViewContainerRef,
bindings: ResolvedReflectiveProvider[],
dialog: DialogRef<any>): Promise<DialogRef<any>> {
return this._cr.resolveComponent(type)
.then(cmpFactory => {
const ctxInjector = viewContainer.parentInjector;
const childInjector = Array.isArray(bindings) && bindings.length > 0 ?
ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;
return viewContainer.createComponent(cmpFactory, viewContainer.length, childInjector);
})
.then((cmpRef: any) => {
if (dialog.inElement) {
this._renderer.invokeElementMethod(
viewContainer.element.nativeElement,
'appendChild',
[cmpRef.hostView.rootNodes[0]]
);
} else {
document.body.appendChild(cmpRef.hostView.rootNodes[0]);
}
dialog.destroy = () => cmpRef.destroy();
return dialog;
});
}
示例2: render
render(type: Type,
viewContainer: ViewContainerRef,
bindings: ResolvedReflectiveProvider[],
dialog: DialogRef<any>): Promise<DialogRef<any>> {
return this._cr.resolveComponent(type)
.then(cmpFactory => {
const ctxInjector = viewContainer.parentInjector;
const childInjector = Array.isArray(bindings) && bindings.length > 0 ?
ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;
return viewContainer.createComponent(cmpFactory, viewContainer.length, childInjector);
})
.then((cmpRef: ComponentRef<any>) => {
if (dialog.inElement) {
viewContainer.element.nativeElement.appendChild(cmpRef.location.nativeElement);
} else {
document.body.appendChild(cmpRef.location.nativeElement);
}
dialog.onDestroy.subscribe( () => {
if (typeof cmpRef.instance.canDestroy === 'function') {
cmpRef.instance.canDestroy().then ( () => cmpRef.destroy() );
} else {
cmpRef.destroy();
}
});
return dialog;
});
}
示例3: ngOnInit
public ngOnInit() {
// just init the entity for this example
this.entity = {
description: "The description of the user instance, passed as (shared) reference"
};
// dynamic template built (
var template = this.customComponentBuilder
.CreateTemplate();
// now we get built component, just to load it
var dynamicComponent = this.customComponentBuilder
.CreateComponent(template, FORM_DIRECTIVES);
// we have a component and its target
this.componentResolver
.resolveComponent(dynamicComponent)
.then((factory: ComponentFactory<IHaveDynamicData>) => {
// Instantiates a single {@link Component} and inserts its Host View
// into this container at the specified `index`
let dynamicComponent = this.dynamicComponentTarget.createComponent(factory, 0);
// and here we have access to our dynamic component
let component: IHaveDynamicData = dynamicComponent.instance;
component.name = "The name passed to component as a value";
component.entity = this.entity;
});
}
示例4:
.then(m => {
//console.debug(' resolve Compnent :' + eval('m.' + compName));
cr.resolveComponent(eval('m.' + compName)).then(factory => {
//console.debug('callback '+factory);
callback(vcr.createComponent(factory, 0));
});
})
示例5: updateComponent
private updateComponent(transition: boolean = false) {
if (transition) {
this.host.clear();
}
this.resolver
.resolveComponent(this.getStage())
.then((f) => this.initComponent(f));
}
示例6: createPlaceholder
private createPlaceholder() {
this.cmpResolver.resolveComponent(NgGridPlaceholder)
.then((factory:ComponentFactory) => {
this.placeholder = factory
.create(this.viewContainer.injector, undefined, this.window.document.body)
.instance;
});
}
示例7: instanciate
/**
*
* @param componentType
* @param viewContainer
* @param injector
*
* @return {null}
*/
public instanciate(componentType : Type, viewContainer : ViewContainerRef, injector : Injector = null) : Promise<ComponentRef<any>> {
let componentRef;
return this.componentResolver.resolveComponent(componentType).then(factory => {
componentRef = viewContainer.createComponent(factory, viewContainer.length, injector || viewContainer.parentInjector);
}).then(() => {
return componentRef;
});
}
示例8:
(resolve, reject) => {
let componentClass = this.registry.getWidgetType(type);
this.resolver.resolveComponent(componentClass).then(
componentFactory => {
let component = container.createComponent(componentFactory);
resolve(component);
}
);
}
示例9: ngOnInit
ngOnInit() {
this.componentResolver.resolveComponent(Item1Component).then(factory => {
// console.log(this.vs);
let res = this.vc.createComponent(factory);
//res.instance.setCoordinates(coordinates.first, coordinates.second);
});
}
示例10: _loadTreeNodeContent
_loadTreeNodeContent() {
this.componentResolver.resolveComponent(this.treeModel.treeNodeContentComponent)
.then((componentFactory: ComponentFactory<{ node: TreeNode }>) => {
let componentRef: ComponentRef<{ node: TreeNode }>
= this.viewContainerRef.createComponent(componentFactory, 0, this.viewContainerRef.injector);
componentRef.instance.node = this.node;
componentRef.changeDetectorRef.detectChanges();
});
}