에 온 클릭 이벤트 APPEND 구성 요소 나 각도 5를 사용하고 있는데이 있습니다각도 5 - 사업부
// app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
appendToContainer() {
// Do the stuff here
// Append PanelComponent into div#container
}
}
이제 app.component.html
// app.component.html
<button (click)="appendToContainer()"></button>
<div id="container"></div>
그리고 마지막으로 내가 간단한 구성 요소가를
// panel.component.html
<div class="panelComponent">
This is a panel Component html
</div>
내가하고 싶은 그 때마다 내가 panel.component의 APPE 필요 클릭 app.component.html에있는 버튼입니다 app.component.html에 첨부 됨
어떻게해야합니까?
을 원하는 달성하기 위해 * ngFor과 변수를 사용할 수 있습니다. '* ngFor'를 사용하여 배열을 반복해서는 안됩니까? –
당신은'appendToContainer'를 호출 할 때 추가 할 수있는 객체 배열을 사용할 수 있으며 배열의 각 항목에 대한 패널을 만들기 위해'* ngFor'를 사용합니다. – FabioG
무엇을하고 싶습니까? 컴포넌트에 새로운 인스턴스를 만들고 추가합니다. 단추를 클릭 할 때 div 안에 – pedromartinez