Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

In my app i want to add dynamic number to each class of div for creating a dynamic twitter bootstrap grid class.for example col-md-2 or col-md-3. and then repeat from these div :

 <div class="row" ng-repeat="row in placeholders">
        <div class="col-md-12">
            <div ng-repeat="column in row.columns" class="col-md-{{12 / row.columns.length}} biki"></div>
        </div>
    </div>

and this is the model :

  $scope.placeholders = [{
            name: "Row 1",
            showName: true,
            columns: [{
                name: "Col1 in Row 1",
            }, {
                name: "Col2 in Row 1"
            }]

    }, {
            name: "Row 2",
            showName: true,
            columns: [{
                name: "Col 1 in Row 2",
            }, {
                name: "Col 2 in Row 2"
            },
             {
                name: "Col 3 in Row 2"
            }]

    }]

So if the length of columns array in object is 6 it divided by 12 and create 6 div with col-md-2 class. The problem happen when length of array is 5 or 8. If 5 the number is divided by 12 is 2.4 and twitter bootstrap have not any value for 2.4 so I want to parseInt or solve the problem with other way but I don't know how to do it.

share|improve this question
    
use Math.ceil() to round up. See MDN docs – charlietfl May 18 '14 at 18:03
    
I can not use Math.ceil() or ParseInt() in angular expression it dose'nt work – MBehtemam May 18 '14 at 18:07
    
can simply use a scope function in expression class="{{getClass(row)}}" – charlietfl May 18 '14 at 18:10
1  
This can be fixed using a filter. Demo : jsbin.com/bahoze/4/edit – mohamedrias May 18 '14 at 18:31
up vote 1 down vote accepted

DEMO

Create this filter:

myApp.filter('parseInt', function () {
    return function(a,b){
        return(parseInt(a))
    }
});

Now in your view:

class="col-md-{{12 / row.columns.length | parseInt}} biki"

This will do the trick :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.