Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 角度-通过按钮显示数组列表中的隐藏值_Arrays_Angular_List - Fatal编程技术网

Arrays 角度-通过按钮显示数组列表中的隐藏值

Arrays 角度-通过按钮显示数组列表中的隐藏值,arrays,angular,list,Arrays,Angular,List,我正在处理web应用程序中的值列表。在这里,我面临着以下问题: app.component.html 这部分代码以列表的形式显示我的数组: 您可以将5保留在某个变量中,然后单击“ShowAll()”,您可以使用*ngIf来增加限制。 您应该将数组切片到5,并存储到另一个变量中。 用户单击按钮以显示所有数据后,将整个数组分配给新变量 public showAll(){ this.newData = this.data; } 例如: this.data = [1,2,3,4,5

我正在处理web应用程序中的值列表。在这里,我面临着以下问题:

app.component.html

这部分代码以列表的形式显示我的数组:


您可以将5保留在某个变量中,然后单击“ShowAll()”,您可以使用
*ngIf
来增加限制。 您应该将
数组
切片到5,并存储到另一个变量中。 用户单击按钮以显示所有数据后,将整个
数组
分配给新变量

 public showAll(){
      this.newData = this.data;
   }
例如:

this.data = [1,2,3,4,5,6,7,8,9,10];
this.newData = data.slice(0,5);
然后在
component.html
文件中:

<div class="body__tags">
  <ng-container *ngFor="let tag of newData; let i=index">
    <li class="tags__list" [label]="tag"></li>
  </ng-container>
</div>

谢谢!很好用!当我再次点击按钮时,我需要添加什么来隐藏其他的?再次切片
数据
并分配给
新数据
你能举个例子吗?@macintosh11你可以引入一个
布尔
标志
isAllVisible
。当标志为
true
时,切片数组并分配给
newData
,否则分配整个数据。最后,
切换
时,
将全部可见
标志值。
<div class="body__tags">
  <ng-container *ngFor="let tag of newData; let i=index">
    <li class="tags__list" [label]="tag"></li>
  </ng-container>
</div>
 public showAll(){
      this.newData = this.data;
   }