"FancyButton"と定義されたコンポーネントがあります。私は、テンプレートにここでそれを持っている:angle2のコンポーネントを動的に削除して追加するにはどうすればよいですか?
...
<div class="container">
<div class="fancy">
<fancybutton></fancybutton>
</div>
<button (click)="removeFancyButton">Remove</button>
<button (click)="addFancyButton">Add</button>
</div>
...
私の質問は、どのように私はプログラム的に削除することができますされています
<div class="fancy">
<fancybutton></fancybutton>
</div>
私は、削除ボタンをクリックすると?逆に、私はどのようにそれを戻しますか?可能であればngOnDestroyをトリガーし、「再追加」するとngOnInitが再び追加されたときにトリガーされます。
これは私のファンシーボタンコンポーネントです。 home.component.html内での統合:
@Component({
selector: 'fancy-button',
template: `<button>clickme</button>`
})
export class FancyButton {}
@Component({
selector: 'home', // <home></home>
providers: [
Title
],
styleUrls: [ './home.component.css' ],
templateUrl: './home.component.html'
})