It is very simple, with the $watch scope directive for your variable (defined in the attribute of your element), and when you change it, you change the value in your element attribute.
Sample code plnkr.co
HTML:
<div class="progress"> <div class="progress-bar" role="progressbar" progress-bar-watch="progress" progress-bar aria-valuenow="" aria-valuemin="0" aria-valuemax="100" style=""></div> </div>
Js
app.controller('MainCtrl', function($scope) { $scope.progress = 0; // Just to show that changing the value dynamically updates the DOM.. var reversing = false; window.setInterval(function() { $scope.$apply(function() { if (reversing) { $scope.progress -= 1; } else { $scope.progress += 1; } if ($scope.progress >= 100) { reversing = true; } else if ($scope.progress <= 0) { reversing = false; } }); }, 100) }) .directive('progressBar', function() { return { restrict: 'A', link: function(scope, element, attrs) { var watchFor = attrs.progressBarWatch; // update now var val = scope[watchFor]; element.attr('aria-valuenow', val) .css('width', val+"%"); // watch for the value scope.$watch(watchFor, function(val) { element.attr('aria-valuenow', val) .css('width', val+"%"); }) } } })
source share