我想完成的是显示数组中的所有元素。该数组包含各种类型的组件(是,组件),并且所有这些组件都从一个抽象类扩展而来。这里是我的代码: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我编辑了澄清问题 –