Change bootstrap progress-bar width from angularjs

后端 未结 5 1605
臣服心动
臣服心动 2020-12-09 04:20

I\'m new in Angularjs and I am trying to update the width of a progress bar when a value in my controller change.

I have something like:



        
5条回答
  •  囚心锁ツ
    2020-12-09 04:56

    I would use a directive for this, that is responsible for calculating the width by itself.

    module.directive("progressbar", function () {
        return {
            restrict: "A",
            scope: {
                total: "=",
                current: "="
            },
            link: function (scope, element) {
    
                scope.$watch("current", function (value) {
                    element.css("width", scope.current / scope.total * 100 + "%");
                });
                scope.$watch("total", function (value) {
                    element.css("width", scope.current / scope.total * 100 + "%");
                })
            }
        };
    });
    

    http://jsfiddle.net/rGWUR/10/

提交回复
热议问题