好吧,我真的很菜鸟,所以我问这是正确的方法还是有更简单的方法。
我想要的是根据值向元素添加一个类......所以我接下来要做的是:
HTML:
<progress value="{{ luminaria.nivelcargabateria }}"></progress>
指令定义:
angular.module('angularJSApp')
.directive('progress', function () {
return {
restrict: 'E',
replace: true,
templateUrl: 'views/progress.html',
scope: {
value: '@'
},
controller: function ($scope) {
$scope.barClass = function () {
return ($scope.value > 66)?'success':($scope.value > 33)?'warning':'danger';
}
}
};
});
指令模板:
<div class="progress">
<div class="progress-bar progress-bar-{{ barClass() }}" role="progressbar" aria-valuenow="{{ value }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ value }}%">
<span class="sr-only">{{ value }}%</span>
</div>