首页 > 解决方案 > How to enable vertical scroll when more data is loaded in the sub component in form of gridcontrols?

问题描述

When i am opening the component there is a sub component that gets array of data objects through api. I need to enable scroll-vertical when the data returned is more than 5 and disable it when the data objects are less than 5.

标签: angular

解决方案


在这里,试试这个:

https://stackblitz.com/edit/angular-2wcotd

基本思想是使用 [ngClass] 条件

<div [ngClass]="{'temp':items.length > 5}">
    <div *ngFor="let item of items">
        {{item}}
    </div>
</div>

<button (click)="add(3)" >Add</button>
<button (click)="remove()" >Remove</button>

在 css 中:

.temp{
  max-height: 200px;
  overflow-y:scroll;
}

推荐阅读