通过单击显示以前的卡片和单击的卡片并隐藏角度 6 中的其他索引 [英] by click show the previous cards and clicked card and hide the other index in angular 6
问题描述
通过显示所有卡片,通过点击卡片点击卡片,以前的卡片应该是可见的,其他的应该是不可见的.我该怎么做?
app.component.html
<div class=" col-md-3" *ngFor="let x of list; let i = index " style="padding:15px;"[隐藏]="x.隐藏"><div class="card"><div class="card-body"><img src="{{x.productImage}}" class="rounded" (click)="display(x)" ><div>{{x.product_name}} {{i}}</div>
app.component.ts
list:object;ngOninit{this.data.getList().subscribe(data => {this.list = 数据;});显示(x){this.list.forEach((x) => x.hidden = true);x.隐藏=假;}
只需使用 TS & 更新堆栈闪电战中的 2 个文件下面的 HTML 代码...要禁用名为list"的列表的 n+1 行,请检查我在显示功能中的评论.
import { Component } from '@angular/core';@成分({选择器:'我的应用',templateUrl: './app.component.html',styleUrls: ['./app.component.css']})导出类 AppComponent {列表:任何[] = [{ productImage: 'https://angular.io/assets/images/logos/angular/logo-nav@2x.png', product_name: 'anguar', visible: true},{ productImage: 'https://angular.io/assets/images/logos/angular/logo-nav@2x.png', product_name: 'anguar', visible: true},{ productImage: 'https://angular.io/assets/images/logos/angular/logo-nav@2x.png', product_name: 'anguar', visible: true},{ productImage: 'https://angular.io/assets/images/logos/angular/logo-nav@2x.png', product_name: 'anguar', visible: true},{ productImage: 'https://angular.io/assets/images/logos/angular/logo-nav@2x.png', product_name: 'anguar', visible: true},]类似:任何[] = [{ productImage: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTZzXqymcb9NZkoJVW9HImoOKbYFfinBRvk8yNWVnCzlqD-fl_h', product_name: 'anguar6', 可见: true},{ productImage: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTZzXqymcb9NZkoJVW9HImoOKbYFfinBRvk8yNWVnCzlqD-fl_h', product_name: 'anguar6', 可见: true},{ productImage: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTZzXqymcb9NZkoJVW9HImoOKbYFfinBRvk8yNWVnCzlqD-fl_h', product_name: 'anguar6', 可见: true},{ productImage: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTZzXqymcb9NZkoJVW9HImoOKbYFfinBRvk8yNWVnCzlqD-fl_h', product_name: 'anguar6', 可见: true},{ productImage: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTZzXqymcb9NZkoJVW9HImoOKbYFfinBRvk8yNWVnCzlqD-fl_h', product_name: 'anguar6', 可见: true},]显示(索引号){console.log("内部显示为:"+indexNumber);for(var i=0; i< this.list.length; i++){if (i==indexNumber || i==indexNumber-1/* 注释下面的行以隐藏要显示的 n+1 项 */||i==索引号+1/* 注释上面的行以隐藏要显示的 n+1 项 */){this.list[i].visible=true;}别的{this.list[i].visible=false;}}for(var i=0; i x.hidden = true);x.隐藏=假;*/}}
<hello name="{{ name }}"></hello><div class="row"><div class=" col-md-3" *ngFor="let x of list; let i = index " style="padding:15px;"><div class="card"><div class="card-body" *ngIf="x.visible"><img src="{{x.productImage}}" class="rounded" (click)="display(i)"/>{{x.product_name}} {{i}}