Skip to content

Instantly share code, notes, and snippets.

@wuliupo
Created October 12, 2016 06:08
Show Gist options
  • Select an option

  • Save wuliupo/4423fa424a69cca8025e04ffcd36f7dd to your computer and use it in GitHub Desktop.

Select an option

Save wuliupo/4423fa424a69cca8025e04ffcd36f7dd to your computer and use it in GitHub Desktop.
Angular demo - show-more
<!doctype html>
<html lang="en" ng-app="demoApp">
<head>
<meta charset="UTF-8">
<title>Angular demo - show-more</title>
<style>
li{list-style:none;}
li .item{display:block;width:200px;margin-bottom:10px;padding:2px 4px;border:1px solid #888;}
li:nth-child(even) .item{background-color:#DDD;}
</style>
</head>
<body ng-controller="demoCtrl">
<h1>Angular demo - show-more</h1>
<hr>
<h3>Implementation 2</h3>
<ul ng-if="true" ng-init="limitToNum = min">
<li ng-repeat="item in items | limitTo: limitToNum">
<span class="item">{{item}}</span>
</li>
<li ng-show="min < items.length">
<button ng-click="limitToNum = (isShowMore ? min : items.length); isShowMore = !isShowMore" ng-class="isShowMore ? 'show-more' : 'show-less'">{{isShowMore ? 'Show less' : 'Show more'}}</button>
</li>
</ul>
<hr>
<h3>Implementation 2</h3>
<ul ng-if="true">
<li ng-repeat="item in items">
<span class="item" ng-if="$index < min || isShowMore">{{item}}</span>
</li>
<li ng-show="min < items.length">
<button ng-click="isShowMore = !isShowMore" ng-class="isShowMore ? 'show-more' : 'show-less'">{{isShowMore ? 'Show less' : 'Show more'}}</button>
</li>
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
<script>
angular.module('demoApp', []).controller('demoCtrl', ['$scope', function($scope){
'use strict';
$scope.items = ['Google', 'IBM', 'Hewlett-Packard', 'Dell'];
$scope.min = 2;
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment