我正在使用angular和bootstrap製作進度條。它現在正常工作,它正確顯示了進度值。現在我希望我的進度條使用types=" "
,具體取決於我稱爲進度的屬性的值。我嘗試從UI Bootstrap和其他一些堆棧溢出示例實現代碼,但我錯過了一些東西。如何根據值更改進度欄顏色?
任何人都可以幫忙嗎?謝謝你的時間。
的script.js
table.controller('workingPlan', function ($scope, $localStorage) {
$scope.$storage = $localStorage.$default({
"todos":[
{ "text":"starting work", "progress":10},
{ "text":"middle of work","progress":50},
{ "text":"lunch brake", "progress":70},
{ "text":"finished working", "progress":100}
]
});
$scope.changeType = function(todo) {
var type;
if (todo.progress < 30) {
type = 'success';
} else if (todo.progress < 60) {
type = 'info';
} else if (todo.progress < 90) {
type = 'warning';
} else {
type = 'danger';
}
$scope.type = type;
};
的index.html
<tr ng-repeat="todo in plan>
<td><progressbar animate="false" value="todo.progress" type="{{todo.type}}"><b>{{todo.progress}}% </b></progressbar></t
</tr>
請注意,你聲明一changeType功能,但你不要在任何地方運行它:) –