Search code examples
angularjsangularjs-ng-repeatng-style

Dynamically set element width based on ng-repeat item count


I am new to use AngularJS 1.4.x .

<div class="colContainer" ng-repeat="item in betNumber" ng-style="{width:{{rowWidth(item.length)}} +'px'}">

when press AddNumber ball more then 13 ,i wish width size can resize . This is my hope enter image description here

i hope can dynamic change div width size ,how to let it work fine ???

This is my hope http://plnkr.co/edit/t8bBjE?p=preview


Solution

  • Change your ng-style value to {width:rowWidth(item.length) +'px'}. That should work.

    The ng-style directive will evaluate the whole object, which means it will use the $parse method to evaluate the expression. So you don't have to use double curly braces.