是否可以合并两个模型/数组并在 angular 6 中用 *ngFor 显示它们?
Is possible to merge two models/ arrays and show them with *ngFor in angular 6?
我正在从服务器获取数据:
ngOnInit() {
this.projectsService.getAllProjects().subscribe(data =>{
this.projectshowAll = data.project;
});
this.projectteamsService.getAllTeams().subscribe(data =>{
this.teamshowAll = data.projectteams;
});
我正在使用 angular-mgl-timeline 包
<mgl-timeline [toggle]="toggle" [alternate]="alternate">
<mgl-timeline-entry *ngFor="let proj of projectshowAll; let i = index; " (expand)="onExpandEntry($event, i)">
<mgl-timeline-entry-header (click)="onHeaderClick($event)">
<div class="headerTitle">Project: {{proj.projectname}}</div>
</mgl-timeline-entry-header>
<mgl-timeline-entry-content>
<div class="headerTitle">
<div>{{proj.projectnumber}}</div>
<div>{{proj.projectteams}}</div>
<div>{{proj.createdBy}}</div>
</div>
</mgl-timeline-entry-content>
<mgl-timeline-entry-dot [class]="color ? 'primary' : 'accent'"
[size]="size"
(click)="onDotClick($event)"></mgl-timeline-entry-dot>
<mgl-timeline-entry-side class="datestyle">Created by: {{proj.createdBy}} At: {{proj.completiondate | date:'MMM dd, yyyy' }} </mgl-timeline-entry-side>
</mgl-timeline-entry>
</mgl-timeline>
目前我可以检索 "projectshowAll" 的数组,我希望同时拥有 "projectshowAll" + "teamshowAll" 并且在创建新项目或团队时进入时间线的顶部.
我搜索了所有内容,但找不到任何适用于 angular 6 的内容,
感谢您的宝贵时间
Its pretty easy in TypeScript if you want to merge Array.
finalArray = [];
ngOnInit() {
this.projectsService.getAllProjects().subscribe(data =>{
this.projectshowAll = data.project;
this.finalArray.push(...this.projectshowAll);
});
this.projectteamsService.getAllTeams().subscribe(data =>{
this.teamshowAll = data.projectteams;
this.finalArray.push(...this.teamshowAll);
});
我不确定 angular-mgl-timeline 是什么,但您似乎在询问如何合并两个数组。使用 Array.prototype.concat()
函数非常简单。 Readmore
如果你想在模板中进行数组合并,你可以这样做:
*ngFor="let proj of projectshowAll.concat(teamshowAll);
我正在从服务器获取数据:
ngOnInit() {
this.projectsService.getAllProjects().subscribe(data =>{
this.projectshowAll = data.project;
});
this.projectteamsService.getAllTeams().subscribe(data =>{
this.teamshowAll = data.projectteams;
});
我正在使用 angular-mgl-timeline 包
<mgl-timeline [toggle]="toggle" [alternate]="alternate">
<mgl-timeline-entry *ngFor="let proj of projectshowAll; let i = index; " (expand)="onExpandEntry($event, i)">
<mgl-timeline-entry-header (click)="onHeaderClick($event)">
<div class="headerTitle">Project: {{proj.projectname}}</div>
</mgl-timeline-entry-header>
<mgl-timeline-entry-content>
<div class="headerTitle">
<div>{{proj.projectnumber}}</div>
<div>{{proj.projectteams}}</div>
<div>{{proj.createdBy}}</div>
</div>
</mgl-timeline-entry-content>
<mgl-timeline-entry-dot [class]="color ? 'primary' : 'accent'"
[size]="size"
(click)="onDotClick($event)"></mgl-timeline-entry-dot>
<mgl-timeline-entry-side class="datestyle">Created by: {{proj.createdBy}} At: {{proj.completiondate | date:'MMM dd, yyyy' }} </mgl-timeline-entry-side>
</mgl-timeline-entry>
</mgl-timeline>
目前我可以检索 "projectshowAll" 的数组,我希望同时拥有 "projectshowAll" + "teamshowAll" 并且在创建新项目或团队时进入时间线的顶部.
我搜索了所有内容,但找不到任何适用于 angular 6 的内容, 感谢您的宝贵时间
Its pretty easy in TypeScript if you want to merge Array.
finalArray = [];
ngOnInit() {
this.projectsService.getAllProjects().subscribe(data =>{
this.projectshowAll = data.project;
this.finalArray.push(...this.projectshowAll);
});
this.projectteamsService.getAllTeams().subscribe(data =>{
this.teamshowAll = data.projectteams;
this.finalArray.push(...this.teamshowAll);
});
我不确定 angular-mgl-timeline 是什么,但您似乎在询问如何合并两个数组。使用 Array.prototype.concat()
函数非常简单。 Readmore
如果你想在模板中进行数组合并,你可以这样做:
*ngFor="let proj of projectshowAll.concat(teamshowAll);