项目里需要一个进度条,所以就在网上查找资料学习,看到了网友“雪狼”的代码分享,写的很高明,很精练,很厉害,原文链接:http://www.ngnice.com/showcase/#/show/progress,结合自己的项目需要,自己改编了个简单的进度条,可以加在项目里面,进度条的开始和结束由自己决定。
var myApp = angular.module('myApp', []);
myApp.controller('main', ['$scope', '$interval', function($scope, $interval){
var vm = $scope.vm = {};
vm.value = 0;
vm.style = 'progress-bar-danger';
vm.showLabel = true;
vm.striped = true;
$scope.selectValue = function (){
console.log(vm.style);
};
var index = 0;
var timeId = 500;
$scope.count = function(){
var start = $interval(function(){
vm.value = ++index;
if (index > 99) {
$interval.cancel(start);
}
if (index == 60) {
index = 99;
}
}, timeId);
};
}]);
2. [代码]html
<div ng-class="{progress: true, 'progress-striped': vm.striped}" class="col-md-4">
<div ng-class="['progress-bar', vm.style]" ng-style="{width: vm.value + '%'}">
<div ng-if="vm.showLabel">{{vm.value}}%</div>
</div>
</div>
<button class="btn btn-success" ng-click="count()">开始进度</button>
var myApp = angular.module('myApp', []);
myApp.controller('main', ['$scope', '$interval', function($scope, $interval){
var vm = $scope.vm = {};
vm.value = 0;
vm.style = 'progress-bar-danger';
vm.showLabel = true;
vm.striped = true;
$scope.selectValue = function (){
console.log(vm.style);
};
var index = 0;
var timeId = 500;
$scope.count = function(){
var start = $interval(function(){
vm.value = ++index;
if (index > 99) {
$interval.cancel(start);
}
if (index == 60) {
index = 99;
}
}, timeId);
};
}]);
2. [代码]html
<div ng-class="{progress: true, 'progress-striped': vm.striped}" class="col-md-4">
<div ng-class="['progress-bar', vm.style]" ng-style="{width: vm.value + '%'}">
<div ng-if="vm.showLabel">{{vm.value}}%</div>
</div>
</div>
<button class="btn btn-success" ng-click="count()">开始进度</button>