Despite the possibility of this being considered a duplicate, none of the related topics have provided a solution to my simple date count down directive:
class Clock {
constructor() {
this.restrict = 'AC';
this.replace = true;
this.template = require('./templates/clock.tpl.html');
this.scope = {};
}
link(scope, elem, attrs, $interval) {
let end = new Date('05/05/2017 9:00 AM');
let _second = 1000;
let _minute = _second * 60;
let _hour = _minute * 60;
let _day = _hour * 24;
scope.showRemaining = () => {
let now = new Date();
let distance = end - now;
let days = Math.floor(distance / _day);
let hours = Math.floor((distance % _day) / _hour);
let minutes = Math.floor((distance % _hour) / _minute);
let seconds = Math.floor((distance % _minute) / _second);
scope.days = days;
scope.hours = hours;
scope.minutes = minutes;
scope.seconds = seconds;
}
$interval(showRemaining, 1000;)
}
}
// create factory function to handle DI
function factory() {
"ngInject";
return new Clock();
}
export default factory;
I've been searching for a solution to this issue and everywhere I find information stating that the interval function must be passed as a normal one without parameters or any additional features. However, I continue to encounter the same error message:
TypeError: $interval is not a function
Can someone provide assistance?