Angularjs Get first and last value of list-item (li)

Today, We want to share with you Angularjs Get first and last value of list-item (li).In this post we will show you Angular ngFor, ng-template and the compiler, hear for Add a class to last 3 list items in AngularJS we will give you demo and example for implement.In this post, we will learn about Show only first and last child as result inside `ng-repeat` with an example.

Angularjs Get first and last value of list-item (li)

There are the Following The simple About angularjs show last 5 items in ng-repeat list Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to get last value of array in angularjs, so the Angular NgFor: Everything you need to know is used for this example is following below.

Read Also:  VueJS setTimeout() Function Examples

How to get the last record in an array in AngularJS?

{{ObjectsArr[ObjectsArr.length - 1]}}

var app = angular.module('app', ['ui.bootstrap']);
app.controller('productCtrl', function ($scope) {
	$scope.data = [1,2,3]
});

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.0/ui-bootstrap-tpls.min.js"></script>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body >
  <div ng-app="app">
    <div ng-controller="productCtrl">
<ul>
      <li ng-repeat="item in product" ng-if="$last">{{item}}</li>
</ul>
    </div>
    </div>
</body>
</html>

angularjs show last 5 items in ng-repeat list

using limitTo: -5

<div ng-repeat="product in products | limitTo: -1">
    {{product.name}}
</div>

<li ng-repeat="p in product | limitTo:-5 | orderBy:'time':true">...</li>

ng-repeat show only last element

Read Also:  PHP change Laravel Date Formats Example

<div ng-repeat="n in [data[data.length-1]] track by $index">
    <span>{{n}}</span>
</div>

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about angular 6 get last element of array.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *