Home > Article > Web Front-end > Angular implements progress bar function code sharing
The project needs a progress bar, so I searched for information on the Internet to learn. This article will share with you the code for implementing the progress bar function in Angular. I hope it can help you.
HTML part:
<div ng-class="{progress: true, 'progress-striped': vm.striped}"> <div ng-class="['progress-bar', vm.style]" ng-style="{width: vm.value + '%'}"> <div ng-if="vm.showLabel">{{vm.value}}%</div> </div> </div> <h3>选项</h3> <label>进度:<input type="number" class="form-control" ng-model="vm.value"/></label> <button class="btn btn-primary" ng-click="vm.value=0">0%</button> <button class="btn btn-primary" ng-click="vm.value=20">20%</button> <button class="btn btn-primary" ng-click="vm.value=60">60%</button> <button class="btn btn-primary" ng-click="vm.value=100">100%</button> <hr/> <label>斑马纹<input type="checkbox" ng-model="vm.striped"/></label> <label>文字<input type="checkbox" ng-model="vm.showLabel"/></label> <hr/> <label>风格: <select ng-model="vm.style" class="form-control"> <option value="progress-bar-success">progress-bar-success</option> <option value="progress-bar-info">progress-bar-info</option> <option value="progress-bar-danger">progress-bar-danger</option> <option value="progress-bar-warning">progress-bar-warning</option> </select> </label>
JS part:
?
'use strict'; angular.module('ngShowcaseApp').controller('ctrl.show.progress', function ($scope) { var vm = $scope.vm = {}; vm.value = 50; vm.style = 'progress-bar-info'; vm.showLabel = true; });
Combine your own projects here If necessary, I adapted a simple progress bar myself, which can be added to the project. The start and end of the progress bar are decided by myself.
1. js code
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 code
<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>
More readers interested in AngularJS related content You can view the special topics on this site: "AngularJS command operation skills summary", "AngularJS entry and advanced tutorial" and "AngularJS Summary of MVC Architecture》
Related recommendations:
WeChat applet implementation of circular progress bar example sharing
clip in css3 Implement the ring progress bar
Javascript timer implements the progress bar function
The above is the detailed content of Angular implements progress bar function code sharing. For more information, please follow other related articles on the PHP Chinese website!