将计算结果设置为ng样式标签Angular.js的百分比

Set result of computation to be percent in ng-style tag Angular.js

本文关键字:Angular 标签 js 百分比 样式 ng 计算 结果 设置      更新时间:2023-09-26
    <div class="vote-percent-container" flex layout="row">
        <div class="percent-red"  ng-style="'width: (vm.lcs.redVotes / vm.lcs.voteSum) * 100%'"></div>
        <div class="percent-blue" ng-style="'width: (vm.lcs.blueVotes / vm.lcs.voteSum) * 100%'"></div>
    </div>

如何将div 的宽度设置为计算值,并且仍然将其设置为百分比。任何帮助将不胜感激

你正在用一个字符串包装你的风格。它应该是一个对象,键作为CSS属性,值作为其值。此外,在计算完实际数字后添加"%"。

试试这个:

<div class="percent-red" ng-style="{'width' : ((vm.lcs.redVotes / vm.lcs.voteSum) * 100 ) + '%'}" > </div>

并在此处查看更多文档。