我有ng-repeat,为每次出现创建div。 我想动态设置大小,它将在整个父元素中传播。
类似的东西:
ng-repeat="widget in widgets"
style="display:inline-block;
border:none;width:100/{{widgets.length}}%"
我想在我的html中而不是在js
中这样做是否可能?
答案 0 :(得分:1)
使用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>
详细说明:ng-style in stackoverflow
更新:
<img src="http://www.gettyimages.in/CMS/StaticContent/1391099215267_hero2.jpg" ng-style="{width: item.value+'%'}" >
选中第一个复选框,查看为图片应用的样式:Fiddle Example