>  기사  >  웹 프론트엔드  >  Angular는 진행률 표시줄 기능 코드 공유를 구현합니다.

Angular는 진행률 표시줄 기능 코드 공유를 구현합니다.

小云云
小云云원래의
2018-02-23 09:51:091724검색

프로젝트에는 진행률 표시줄이 필요하므로 알아보기 위해 인터넷에서 정보를 검색했습니다. 이번 글에서는 Angular에서 진행률 표시줄 기능을 구현하는 코드를 공유해 드리겠습니다.

HTML 부분:

<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>

JS 부분:

?

&#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;
});

내 프로젝트 요구에 따라 프로젝트의 시작과 끝을 추가할 수 있는 간단한 진행률 표시줄을 직접 조정했습니다. 진행률 표시줄은 스스로 결정합니다.

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);
  };
}]);

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>

AngularJS와 관련된 더 많은 콘텐츠에 관심이 있는 독자는 이 사이트의 특별 주제인 "AngularJS 명령 작동 기술 요약"을 확인할 수 있습니다. AngularJS 시작 및 고급 시작하기" 튜토리얼" 및 "AngularJS MVC 아키텍처 요약》

관련 권장 사항:

WeChat 애플릿에서 순환 진행률 표시줄 구현 공유 예

css3의 클립이 링 진행률 표시줄을 구현함

javascript 타이머가 진행률 표시줄 기능을 구현함

위 내용은 Angular는 진행률 표시줄 기능 코드 공유를 구현합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.