ビューでコンポーネントを動的に表示するには、どのような方法が適していますか?動的コンポーネント
例として、ナビゲーションとビューを持つコンポーネントがあります。ナビゲーション内のボタンをクリックすると、ビュー内にさまざまなサブコンポーネントが表示されたり消えたりするはずです。各サブコンポーネントは異なるタイプのサブコンポーネントです。
import { Component, Input } from '@angular/core';
import { Controls } from './controls.service';
@Component({
selector: 'Controlpanel',
templateUrl: 'app/templates/controlPanel.component.html',
directives: Controls.directives()
})
export class ControlPanelComponent {
controls = Controls.objects;
activeControl:string = Controls.objects[0].name;
}
-
<nav class="container-fluid">
<div class="row">
<a *ngFor="let control of controls" (click)="toggleControl(control.name, $event)" role="button" href="#" class=" text-uppercase">
{{control.name}}
</a>
</div>
</nav>
<div>
<this is where i want the sub-component to appear/>
</div>
はhttp://stackoverflow.com/questions/36325212/angular-2-dynamic-tabs-with-userのDUPのような音-click-selected-components/36325468#36325468これは実際に指令やコンポーネントについてですか?ディレクティブを動的に追加/削除することはできません。 –