0

I have ng-repeat that creates div for each occurrence. I want to set the size in % dynamically that it will spread through the whole parent element.

Something like:

ng-repeat="widget in widgets" 
style="display:inline-block;
       border:none;width:100/{{widgets.length}}%" 

And I want to do it in my html and not in js

Is it at all possible?

Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
AlexD
  • 4,062
  • 5
  • 38
  • 65

1 Answers1

1

Use ng-style , ngStyle in angularjs

<div ng-repeat="widget in widgets" >
<span ng-style="{display:'inline-block', 
       border:'none', width:100/widgets.length+'%'}" </span>
</div>

Detailed explanation : ng-style in stackoverflow

Update :

<img src="http://www.gettyimages.in/CMS/StaticContent/1391099215267_hero2.jpg" ng-style="{width: item.value+'%'}" >

Check the first check box and see the style applied for the image : Fiddle Example

Community
  • 1
  • 1
  • Thanks! I'm having a hard time running this though, it evaluates wrong or something. I tried changing it to: ng-style="{'display':'inline-block', 'border':'none','width':100/{{widgets.length}} + '%'}" since angular expects there , instead of ; but still nothing. Any ideas? – AlexD Jan 28 '15 at 10:51