2017-10-28 18 views
1

동적 위치를 #localvariable (<input type='button' #localvariable (click)='doSomething()'>)없이 특정 위치에 추가 할 수있는 방법이 있습니까?#localvariable없이 특정 위치에 요소 컴파일

<td></td> 

컴파일 후 : 주어진 예

https://angular.io/api/core/ComponentFactory#create

constructor(private resolver: ComponentFactoryResolver, private injector: Injector) {} 

ngAfterViewInit() { 
    let factory = this.resolver.resolveComponentFactory(MyDynamicComponent); 
    let compRef = factory.create(injector, [], '#idOfTarget'); 
} 

참조 :

<td><input type='button' (click)='doSomething()'></td> 

답변

0

ComponentFactory.create 대상 파라미터로서 선택 또는 노드를 통과 할 수 있도록

+1

그게 효과가있어. 고맙습니다. –

+0

'ComponentFactory.create'사용하기 어떻게 데이터를 구성 요소에 전달할 수 있습니까? 그리고 내 두 번째 질문은 구성 요소 대신 문자열로 요소를 전달할 수 있습니까? –

+0

'compRef.instance.someField = 'foo';'https://stackoverflow.com/questions/36325212/angular-2-dynamic-tabs-with-user-click-chosen-components/36325468#36325468은 해. –