Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ul LI Binding with AngularJs

Tags:

angularjs

I am new to AngularJs . I want repeated UL and each UL having two LI . In Model, I have array of Customer Object.

Customers =[{Customer:1},{Customer:2},{Customer:3},{Customer:4},{Customer:5}];

In View I want like below,

<ul><li>1</li><li>2</li></ul>
<ul><li>3</li><li>4</li></ul>
<ul><li>5</li></ul>
like image 705
DurGesh kuMar RAO Avatar asked Apr 12 '26 07:04

DurGesh kuMar RAO


1 Answers

There you go: http://jsfiddle.net/F45Db/

    <ul ng-repeat="c in dummy track by $index" ng-class="{last: $last}">
        <li ng-repeat="cust in Customers"
            ng-if="$index >= $parent.$index*2 && $index < $parent.$index*2 + 2">
             {{cust.Customer}}
        </li>
    </ul>

js:

function Controller($scope){
    $scope.Customers = [{Customer:1},{Customer:2},{Customer:3},{Customer:4},{Customer:5}];
    $scope.$watchCollection('Customers', function(){
        if($scope.Customers.length){
            $scope.dummy = new Array(Math.ceil($scope.Customers.length/2));
        }
    });
}
like image 200
kamilkp Avatar answered Apr 13 '26 21:04

kamilkp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!