Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Understanding ng-repeat special variables in AngularJS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 410
    Comment on it

    Hello Readers,

    Hope you are doing good today.

    Today on My blog, I am going to explain about the ng-repeat special variables in AngularJS. The nag-repeat directive has a set of special variables which can be used while iterating the collection.

    These Special variables are:





    In below code we are iterating the collection of friends and checking the position of value with the help of ng-repeat special variables.

    <div ng-app="app" ng-controller="ctrl">
    						 <li ng-repeat="friend in friends">
    //The $first, $middle and $last returns a boolean value depending on whether the current item is the first, middle or last element in the collection being iterated.
    								 <span ng-if="$first">
    								 	<strong>{{}} (first element found)</strong>
    								 <span ng-if="$middle">
    								 	<strong>{{}} (middle element found)</strong>
    								 <span ng-if="$last">
    								 	<strong>{{}} (last element found)</strong>

    In below script we create the friends array.

    var app = angular.module("app", []);
     app.controller("ctrl", function ($scope) {
     $scope.friends = [{ name: 'Rafi', gender: 'boy' },
    		 { name: 'Kajal', gender: 'girl' },
    		 { name: 'deepak', gender: 'boy' },
    		 { name: 'sonam', gender: 'girl' }];

    I hope this will help you. Please feel free to give us your feedback in comments.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: