我想完成的是顯示數組中的所有元素。該數組包含各種類型的組件(是,組件),並且所有這些組件都從一個抽象類擴展而來。這裏是我的代碼:Angular 2顯示混合元素array
抽象類插件
export abstract class Plugin {
constructor() { }
}
關注組件
@Component({
selector: 'watch',
template: `
{{clock | async | date:'medium'}}
`
})
export class WatchCmpt extends Plugin {
clock = Observable.interval(1000).map(() => new Date())
constructor() {
super();
}
}
演示組件
@Component({
selector: 'demo',
template: `
<h1>Hello {{name}}</h1>
`
})
export class DemoCmpt extends Plugin {
name: string = "Jose";
constructor() {
super();
}
}
我用在我看來,這段代碼中顯示它我html文件:
<? *ngFor="let target of targetList; let x = index">{{target}} </?>
我應該在<?>
中使用什麼?
targetList
是一個數組是這樣的: [demo, watch]
編輯:
@Component({
selector: 'dndPanel',
templateUrl: 'dragNdropPanel.cmpt.html'
})
export class DragNDropPanelCmpt {
@ViewChild(DemoCmpt) demo1: DemoCmpt;
@ViewChild(WatchCmpt) watch: WatchCmpt;
constructor() {
}
targetList: Plugin[] = [
this.demo1,
this.watch,
];
addTo($event: any) {
this.targetList.push($event.dragData);
}
}
這是完整的HTML
div class="col-sm-6">
<div class="panel panel-info" dnd-sortable-container [sortableData]="targetList">
<div class="panel-heading">Target List</div>
<div class="panel-body" dnd-droppable (onDropSuccess)="addTo($event)" [dropZones]="['source-dropZone']">
<ul class="list-group">
<li *ngFor="let target of targetList; let x = index" class="list-group-item" dnd-sortable [sortableIndex]="x" [dragEnabled]="true">
{{target}}
</li>
</ul>
</div>
</div>
</div>
在哪裏'targetList'聲明? – Aravind
@Aravind我編輯了澄清問題 –