【发布时间】:2018-01-12 19:50:19
【问题描述】:
我想要完成的是显示数组中的所有元素。该数组包含各种类型的组件(是的,组件),所有这些组件都从一个抽象类扩展而来。
这是我的代码:
抽象类插件:
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 我编辑了问题以便澄清
标签: javascript html arrays angular