Reputation: 7856
I would like to send the component from within the component meaning when I have this:
@Component({
selector: 'my-component',
templateUrl: 'my.template.html'
})
export class MyComponent {
private myVar: any;
constructor(){
}
myFunction() =>{
}
}
Outside of the class I can simply call:
import { MyComponent } from './my.component';
But I would like to get MyComponent
within the class:
myFunction() =>{
this.myVar = **MyComponment**
}
How to get **MyComponent**
?
Please note that I don't want the instance but need the class itself.
EDIT: I realize my question is not clear enough. Here is what I need to do... I need to extract the component and recreate it somewhere else. In another component I have the following:
export class MyOtherComponent {
constructor(private viewContainer: ViewContainerRef, private componentFactoryResolver: ComponentFactoryResolver){
}
createComponent(myComponent) =>{
var factory = this.componentFactoryResolver.resolveComponentFactory(myComponent);
var compRef = this.viewContainer.createComponent(factory);
container.getElement().append($(compRef.location.nativeElement));
}
}
So Inside MyComponent
I want to be able to do this:
myFunction() =>{
this.myOtherComponent.createComponent(**MyComponent**)
}
Upvotes: 0
Views: 49