Answer the question
In order to leave comments, you need to log in
Service value not updating in AngularJS directive?
I am using Angular version 1.
There is a directive:
.directive('lives', ['freelive', 'liveNum', '$timeout', function(freelive, liveNum, $interval) {
return {
restrict: 'AE',
replace: true,
freelive: freelive,
templateUrl: 'templates/directives/lives.html',
link: function(scope, elem, attrs) {
scope.liveValue = liveNum.total;
$interval(function() {
liveNum.total = liveNum.total - 1;
console.info('UPDATED!');
}, 3000);
}
};
}]);
angular
.module('starter')
.value('liveNum', {
minimum: 0,
maximum: 20,
oneTouch: 1,
total: 20
});
<div class="live-value">{{liveValue}}</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question