にコンポーネントを追加します。今すぐapp.component.html角度5 - のonclickイベント私は角度5を使用していますが、私はこれ持っているdiv要素
// app.component.html
<button (click)="appendToContainer()"></button>
<div id="container"></div>
と最終的に私は単純なコンポーネントを持っているの
// 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
}
}
を
// 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