javascript - 如何动态分配跨度的宽度

标签 javascript html css angularjs

我是 html 和 angularjs 的新手。这里我试图分配跨度宽度 动态地从 Angular JS 响应

<div class="statarea" ng-repeat="x in names">
     <div class="ratingarea">
        <div class="your-rating"><span style="width:"+{{ x.width }}+";" class="outer"></span>
        </div>
     <div class="clear"></div>
     </div>
</div>

在我的脚本中是

$http.get(url).success(function (response) {
  $scope.names = response;
});

我的回答是

[
 {"width":"78%"},
 {"width":"60%"},
 {"width":"50%"}
]

我知道这不是写的,但我不知道.. 提前致谢

最佳答案

您可以使用ngStyle例如,与其他 Angular 内置指令一样

ng-style="{color: myColor}"

ngStyle 需要 Expression它评估为一个对象,其键是 CSS 样式名称,值是这些 CSS 键的对应值。因此,在您的情况下,您可以将宽度设置为

<div class="statarea" ng-repeat="x in names">
  <span ng-style="x" />
</div>

或者使用范围变量,例如

<div class="statarea" ng-repeat="x in names">
  <span ng-style="{'width': x.width}" />
</div>

关于javascript - 如何动态分配跨度的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28252017/

相关文章:

javascript - Backbone 中的路由器分离

html - 单选按钮在 iPad 上显示不正确

javascript - 如何比较输入的两个日期?

html - 为什么高度没有 : 100% work to expand divs to the screen height?

html - 边框图像不改变宽度

html - 无法以特定方式移动/动画我的 svg Logo

html - 我什么时候应该使用 HTML5 和 CSS3?

javascript - 当突出显示/选择文本中的单词时执行操作

javascript - 将对象(图像)与底部对齐

javascript - HTML5输入类型Color,如何使用javascript更改其值