I have trying to create a AngularJS component corresponding to a progress bar. Here is a JSFiddle created for this question http://jsfiddle.net/Lvc0u55v/6725/
Here is my application and component definition:
var myApp = angular.module('myApp',[]);
myApp.controller('TestController', function($scope) {
$scope.total = 20;
$scope.count = 15;
$scope.changeTotal = function(value){$scope.total += value};
$scope.changeCount = function(value){$scope.count += value};
});
myApp.component('progressBar', {
bindings: {
percentage: '=',
},
controller: function() {
this.width = this.percentage * 100;
},
template: '<div class="progressBar">\
<div class="inner" style="width: [[$ctrl.width]]%"></div>\
</div>',
});
And the following HTML code:
<div ng-app="myApp">
<div ng-controller="TestController">
Total: {{total}}, <button ng-click="changeTotal(-1)">-</button><button ng-click="changeTotal(+1)">+</button><br/>
Count: {{count}}, <button ng-click="changeCount(-1)">-</button><button ng-click="changeCount(+1)">+</button><br/>
Percentage: {{count / total}}%<br/>
<br/>
<progress-bar percentage="{{count / total}}"></progress-bar>
</div>
</div>
Despite the definition of the width
attribute in the component controller, AngularJS can not find it in the template defined.
I have some difficulty to debug this code efficiently since I just started learning AngularJS.