我无法将$ scope中的数据绑定到ui.bootstrap进度条中的value属性
angular.module('app')
.controller('progressbarController', function($scope, dataConstant) {
'use strict';
$scope.dataConstant = dataConstant;
$scope.stock = dataConstant.item.counts.statuses.stock;
$scope.lost = dataConstant.item.counts.statuses.lost;
$scope.progress = dataConstant.item.counts.statuses.progress;
$scope.totalParts = $scope.stock + $scope.lost + $scope.progress;
$scope.calculatePercentage = function() {
var a = dataConstant.item.counts.statuses.stock || 0,
b = dataConstant.item.counts.statuses.lost || 0,
c = dataConstant.item.counts.statuses.progress || 0,
sum = a + b + c,
ab = a / sum,
bc = b / sum,
cd = c / sum,
aPercent = ab.toFixed(2) * 100,
bPercent = bc.toFixed(2) * 100,
cPercent = cd.toFixed(2) * 100;
console.log('stock is ' + aPercent + '% of ' + sum);
console.log('Lost is ' + bPercent + '% of ' + sum);
console.log('progress is ' + cPercent + '% of ' + sum);
$scope.sum = sum;
$scope.aPercent = aPercent;
$scope.bPercent = bPercent;
$scope.cPercent = cPercent;
};
$scope.calculatePercentage();
});
div(ng-controller='progressbarController')
progress(data-total="{{sum}}", value="{{sum}}")
bar(class="stock", value="{{aPercent}}") {{ stock }}
bar(class="lost", value="{{bPercent}}") {{lost}}
bar(class="unconfirmed", value="{{cPercent}}") {{progress}}
为什么aFercent,bPercent或cPercent会绑定到bar元素中的value属性?
答案 0 :(得分:1)
您不必插入绑定到value
属性的表达式。试试这个:
div(ng-controller='progressbarController')
progress(data-total="{{sum}}", value="sum")
bar(class="stock", value="aPercent") {{ stock }}
bar(class="lost", value="bPercent") {{lost}}
bar(class="unconfirmed", value="cPercent") {{progress}}