本文整理匯總了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();
});
}