在Angular 2中,我得到了一个项目列表,并根据给定的条件(即基于位置编号)我设置列表重复.
我需要为每个位置的第一个框隐藏" 删除文本 ".
Plunker: https://plnkr.co/edit/xtX5BjTBjO61sD2tLwWN ?p = preview:
[1]: https://plnkr.co/edit/xtX5BjTBjO61sD2tLwWN?p=preview
Run Code Online (Sandbox Code Playgroud)
import {Component} from '@angular/core';
@Component({
selector: 'app',
template: `
<ul *ngFor="let locdata of locations">
<template ngFor let-item [ngForOf]="items"; let-i=index>
<div *ngIf="item.location==locdata.location">
<div class="title"> location {{ item.location}} <span *ngIf="isNotFirst(item)"> remove </span> </div>
<div class="container"> {{ item.sedule}}</div>
</div>
</template>
</ul>
`
})
export class App {
items: string[];
isNotFirst(item: any) {
return this.items.filter(i => i.location === item.location).map(i => i.id).indexOf(item.id) !== 0;
}
locations:any;
constructor() {
this.locations=[{location:1},{location:2},{location:3}]; …Run Code Online (Sandbox Code Playgroud)