Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add scrollbar using angularJs ng-repeat?

I have angularJS ng-repeat i wanted to add scroll bar to the list items because it might have 4000 character in the field so in that case how can i set scroll bar based on rows or max-height for the div ?

main.html

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-primary">
            <div class="panel-heading clearfix">
                <h3 class="panel-title">Notification<span class="badge">{{tests.length}}</span></h3>
            </div>
            <div class="panel-body">
                <ul>
                    <li class="slide" ng-repeat="test in tests">
                        <div class="alert" role="alert" ng-class="{'alert-info': notification === 'H'}">
                            <span>{{test}}</span>
                        </div>
                    </li>   
                </ul>
            </div>
      </div>    
    </div>
</div>
like image 810
hussain Avatar asked May 16 '16 14:05

hussain


3 Answers

I think this an HTML problem. Try to add this CSS to your code:

.panel-body {
    overflow: scroll;
    height: 100px;
}

overflow is a combination of overflow-x and overflow-y. If you only need to add scrollbars for vertical overflow, only take overflow-y: scroll; If you dont want to see the scrollbar when content small, try overflow: auto.

like image 55
user3601578 Avatar answered Oct 28 '22 18:10

user3601578


I think OP wants to have the scroll when the retrieved data (tests) is a certain value. ng-class is your friend here.

<style>
    .conditionalScroll{
        width: 100%;
        height: 225px; /*change to your liking*/
        overflow: scroll;
    }
</style>
<!-- you may change threshold to your liking as well -->
<div ng-class="{conditionalScroll:tests.length>100}">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-primary">
                <div class="panel-heading clearfix">
                    <h3 class="panel-title">Notification<span class="badge">{{tests.length}}</span></h3>
                </div>
                <div class="panel-body">
                    <ul>
                        <li class="slide" ng-repeat="test in tests">
                            <div class="alert" role="alert" ng-class="{'alert-info': notification === 'H'}">
                                <span>{{test}}</span>
                            </div>
                        </li>   
                    </ul>
                </div>
          </div>    
        </div>
    </div>
</div>
like image 37
chakeda Avatar answered Oct 28 '22 19:10

chakeda


I think you just need to add a style for the class 'panel-body' containining the max-height and overflow value... like the below:

CSS

.panel-body {max-height:400px;overflow:scroll;}

or if you want to add another class so you dont affect the panel-body class then either add a new class in the panel-body on that page like below

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-primary">
            <div class="panel-heading clearfix">
                <h3 class="panel-title">Notification<span class="badge">{{tests.length}}</span></h3>
            </div>
            <div class="panel-body panel-scroll">
                    <ul>
                        <li class="slide" ng-repeat="test in tests">
                            <div class="alert" role="alert" ng-class="{'alert-info': notification === 'H'}">
                                <span>{{test}}</span>
                            </div>
                        </li>   
                    </ul>
            </div>
      </div>    
    </div>
 </div>

CSS

.panel-scroll {max-height:400px;overflow:scroll;} 
like image 2
Christopher Jenks Avatar answered Oct 28 '22 17:10

Christopher Jenks