我知道,你很可能将迎来其视为重复但没有兄弟主题不解决我的问题,所以这是我简单的日期倒计时指令:
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;
我已经bean搜索这个问题的原因,并且无处不在我得到的信息,间隔函数必须作为正常的没有参数或任何其他插件传递。但我仍然有同样的错误,那就是:
TypeError: $interval is not a function
有人能帮忙吗?
通过控制器注入它,而不是链接功能 –