I am working out some code for some application. I want to limit the messages in the chat
this.limitM = -10;
$scope.msgsCount = //contains the number of messages
<button ng-if="msgsCount > -main.limitM"
ng-click="main.limitM=-10+main.limitM">Load More</button>
<li class="singleMessage clearfix"
ng-repeat="msg in chat.msgs | limitTo:main.limitM"
ng-class="::{myMessage: msg.senderName != chat.name}">
<img class="profileImage" alt="::{{chat.name}}" width="40px">
<p ng-bind-html="parseMsg(msg)"></p>
</li>
This is not limiting the messages, all the messages appear. Can anyone help ?
First you have to define all necessary variables to make it work.
Example of your controller:
$scope.limit = 3;
$scope.expand = function(limit) {
$scope.limit += limit;
}
$scope.chat = ['one', 'two', 'three', 'four', 'five', 'six', 'seven'];
And view:
<button ng-if="chat.length > limit" ng-click="expand(limit)">Load More</button>
<li ng-repeat="msg in chat | limitTo : limit" >{{ msg }}</li>
Here is a simple plunk, that does what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With