i have a controller named "HomeCtrl" which calculates the total number of user's into the {{total}}
binding variable, like this:
.controller('HomeCtrl', function($scope, $http){
$scope.total = 0;
});
In my view, I am trying to display my total in an animated widget by passing {{total}}
as the value of an attribute on a <div>
tag, like this:
<div ng-controller="HomeCtrl" ng-init="init('users')">
<div class="xe-widget xe-counter xe-counter-green" xe-counter
data-count=".num" data-from="1"
data-to= "{{total}}"
data-suffix="users" data-duration="3" data-easing="true">
<div class="xe-icon">
<i class="linecons-user"></i>
</div>
<div class="xe-label">
<strong class="num">1k</strong>
<span>Users Total </span>
</div>
</div>
<center> <b> Total utilisateurs : {{total}} </b> </center>
Here is the widget directive:
.directive('xeCounter', function(){
return {
restrict: 'EAC',
link: function(scope, el, attrs)
{
var $el = angular.element(el),
sm = scrollMonitor.create(el);
sm.fullyEnterViewport(function()
{
var opts = {
useEasing: attrDefault($el, 'easing', true),
useGrouping: attrDefault($el, 'grouping', true),
separator: attrDefault($el, 'separator', ','),
decimal: attrDefault($el, 'decimal', '.'),
prefix: attrDefault($el, 'prefix', ''),
suffix: attrDefault($el, 'suffix', ''),
},
$count = attrDefault($el, 'count', 'this') == 'this' ? $el : $el.find($el.data('count')),
from = attrDefault($el, 'from', 0),
to = attrDefault($el, 'to', ''),
duration = attrDefault($el, 'duration', 2.5),
delay = attrDefault($el, 'delay', 0),
decimals = new String(to).match(/\.([0-9]+)/) ? new String(to).match(/\.([0-9]+)$/)[1].length : 0,
counter = new countUp($count.get(0), from, to, decimals, duration, opts);
setTimeout(function(){ counter.start(); }, delay * 1000);
sm.destroy();
});
}
};
})
I can display the correct value of {{total}} in my view, but when I pass {{total}}
into the attribute, as data-to= "{{total}}"
, it does not work. It doesn't recognize it as a number.