How can I round off value in dynamic col-md-(value) in Angular Js?

124 views Asked by At

Hi I have some fields which are coming dynamic and I am adjusting the col-md- according to number of fields. So I wrote an expression some thing like this <div class="col-md-{{12 / variants.length}} Now I want to round off the value. How can I do this ?

2

There are 2 answers

0
Clusi On

In your controller maybe try rounding there instead of on the HTML side?

0
T.Gounelle On

You can use a function defined in the controller, e.g.

<div class="col-md-{{colWidth(variants.length)}}">something</div>

In the controller:

$scope.colWidth = function(nbVariants) {
   // Use whatever formula suits your needs. Be aware that this may return 0
   return Math.round(12/nbVariants);    
}