Home > Web Front-end > JS Tutorial > body text

Angular implements progress bar function code sharing

小云云
Release: 2018-02-23 09:51:09
Original
1781 people have browsed it

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, &#39;progress-striped&#39;: vm.striped}">
 <div ng-class="[&#39;progress-bar&#39;, vm.style]" ng-style="{width: vm.value + &#39;%&#39;}">
  <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>
Copy after login

JS part:

?

&#39;use strict&#39;;
angular.module(&#39;ngShowcaseApp&#39;).controller(&#39;ctrl.show.progress&#39;, function ($scope) {
 var vm = $scope.vm = {};
 vm.value = 50;
 vm.style = &#39;progress-bar-info&#39;;
 vm.showLabel = true;
});
Copy after login

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(&#39;myApp&#39;, []);
myApp.controller(&#39;main&#39;, [&#39;$scope&#39;, &#39;$interval&#39;, function($scope, $interval){
  var vm = $scope.vm = {};
  vm.value = 0;
  vm.style = &#39;progress-bar-danger&#39;;
  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);
  };
}]);
Copy after login

2. html code

<div ng-class="{progress: true, &#39;progress-striped&#39;: vm.striped}" class="col-md-4">
   <div ng-class="[&#39;progress-bar&#39;, vm.style]" ng-style="{width: vm.value + &#39;%&#39;}">
      <div ng-if="vm.showLabel">{{vm.value}}%</div>
   </div>
</div>
<button class="btn btn-success" ng-click="count()">开始进度</button>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template