我知道,你很可能將迎來其視爲重複但沒有兄弟主題不解決我的問題,所以這是我簡單的日期倒計時指令:
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
有人能幫忙嗎?
通過控制器注入它,而不是鏈接功能 –