我正在使用Angular 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>
每次单击app.component.html上的按钮,我想要实现的是将panel.component附加到app.component.html中。如何做到这一点?
*ngFor
迭代一个数组吗? - Deblaton Jean-PhilippeappendToContainer
时将其附加到数组中,并使用*ngFor
为数组中的每个项目创建一个面板。 - FabioG